Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sting Classes  RSS feed

 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s= "REX";
String s= new String("REX");
Both are classes too.
what are the Main Key differences
 
Amgad Muhammad
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rex tony:
String s= "REX";
String s= new String("REX");
Both are classes too.
what are the Main Key differences


String s= "REX";

a string refrence s is created and a string with the REX value is created in the string pool.

String s= new String("REX");

a string refrence s is created and a string with the REX value is created in the string pool, and a String object is created in the heap.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As an aside, there is only one class involved in your examples: java.lang.String. What you have several of are objects, all being instances of that single class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!