File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sting Classes

 
rex tony
Ranch Hand
Posts: 159
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic