This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strings