This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Originally posted by Santosh Jaiswal: The statement ... String s = "Hello" + "Java"; yields the same value for s as ... String s = "Hello"; String s2= "Java"; s.concat( s2 ); 1. True 2.False How the answer is False
Santosh, Answer will be false coz after this statement: String s = "Hello" + "Java"; a String pool will be created which will hold "HelloJava",and variable s will point to that...and when you say String s = "Hello"; String s2= "Java"; s.concat( s2 ); a new pool of String will be created ie HelloJava,but s is still pointing to the other pool of string...now if you say s=s.concat( s2 ); then the answer will be true coz now your variable s is being assigned to a new string which contains "HelloJava"... Hope it clears your doubt.... thanks, Harpal...
Joined: Oct 04, 2000
Oh! I got it, I was just skipping the assignment part. Thanks Harpal.