aspose file tools*
The moose likes Java in General and the fly likes String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "String" Watch "String" New topic
Author

String

Bikram. nsec
Greenhorn

Joined: Feb 17, 2011
Posts: 1

what is difference between String object and string literals??


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

sudheer kiran
Ranch Hand

Joined: Jun 26, 2008
Posts: 237

that the difference between you and your name.

you are an object.
you name is constructed with literals...


Sudheer
SCWCD, SCJP 5
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Oct 27, 2005
Posts: 19784
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: String