File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strings" Watch "Strings" New topic
Author

Strings

sabah ammar
Greenhorn

Joined: Jan 10, 2005
Posts: 23
Hi ,
I am not very sure how do strings perform in memory when == is tested with attributes.
please explain whatever u can . thanks
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The String methods create a new, unique String only when they change the string they are called on.

"String".trim() does not change the string, so you get back a reference to "String" in the string literal pool.

All of your specific examples have this same effect.

== checks for the same object, so comparing two references to the same string in the string literal pool returns true


Mike Gershman
SCJP 1.4, SCWCD in process
 
wood burning stoves
 
subject: Strings