This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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