This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Confusion with strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Confusion with strings" Watch "Confusion with strings" New topic
Author

Confusion with strings

Kitty Dayal
Ranch Hand

Joined: Jul 22, 2004
Posts: 89
Hi,



Code compiles fine, but does not print anything.

Am right with my understanding and what am i missing here?

Thanks a lot.
Kits
Tybon Wu
Ranch Hand

Joined: Jun 18, 2002
Posts: 84
Here are the correct comments for the code:



SCJP2
Kitty Dayal
Ranch Hand

Joined: Jul 22, 2004
Posts: 89
Originally posted by Tybon Wu:

Thanks for reply. But my question was related to duplication of objects in the pool. Since there is already a "abc" present, Will it not use it? Or Why does it not use it here?

Since this is true
[/QB]
Tybon Wu
Ranch Hand

Joined: Jun 18, 2002
Posts: 84
Originally posted by Kitty Dayal:
Thanks for reply. But my question was related to duplication of objects in the pool. Since there is already a "abc" present, Will it not use it? Or Why does it not use it here?


The objects in the pool are used only in constant expressions or by calling the intern() method. Since x.concat("c") is calculated at runtime, objects in the pool are not used. Let me give you a few more examples:
Kitty Dayal
Ranch Hand

Joined: Jul 22, 2004
Posts: 89
Hi Tybon,

Thanks for the usefull information.
Kiran.
Mohit Agarwal
Ranch Hand

Joined: Mar 30, 2004
Posts: 88
Thanks to both of you , to kiran fort posting this doubt and to Tybon Wu
for clearing it out. Mr. Tybon Wu
can you throw some light on intern() method as i had heard about it for the first time.
 
wood burning stoves
 
subject: Confusion with strings
 
Similar Threads
String equality
String Pooling & String Constructors
string constant pool
About Strings...
Doubt in K&B SCJP 5: topic Important Facts About Strings and Memory