This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes is getting me confused Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is getting me confused " Watch "is getting me confused " New topic
Author

is getting me confused

vinayak manda
Ranch Hand

Joined: Jul 27, 2004
Posts: 31
vinayak manda
Ranch Hand

Joined: Jul 27, 2004
Posts: 31
I'am sorry, I couldn't post the question before...

The question is when String s3 gets the value "EFG" and later s4 also gets the value "EFG", as the literal goes into the string pool,then s3 and s4 should point to the same reference.
Then why should (s3 == s4) return false.

Please clear this doubt.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
s3 gets a reference to a new String("EFG") and s4 gets a reference to another new String("EFG"). So s3 and s4 refer to different objects. Therefore s3 == s4 results in false.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Only String literals go into the pool by default. You can use the intern() method for the others to enforce them to get into the pool, too.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
Consider Paul's rocket mass heater.
 
subject: is getting me confused
 
Similar Threads
General problems..
Doubt on Strings
string assignment
subString
Why doesnt this compile?