This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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.