• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String

 
Bikram. nsec
Greenhorn
Posts: 1
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is difference between String object and string literals??


then why we create a string object using new operator???

 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that the difference between you and your name.

you are an object.
you name is constructed with literals...
 
Campbell Ritchie
Sheriff
Pie
Posts: 49805
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that is a good analogy, I am afraid. A literal is a value one can read directly from the code. So "JavaRanch" is a String literal in Java™ Code. That means a String whose value one can see. In statements like . . . "JavaRanch" is used as a String literal (and that is a String object, too), and the same String object (under the name of s) is used in three other places. "CodeRanch" is also a String literal in that code.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any String literal is a String object. String objects don't need to be String literals - they can be created using one of the explicit String constructors, or returned by any method (like String.substring).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic