11. The statement ... String s = "Hello" + "Java"; yields the same value for s as ... String s = "Hello"; String s2= "Java"; s.concat( s2 ); True False why?? these things really confuse me...
Joined: Feb 09, 2001
Hi Pratiti, False. i) String s = "Hello" + "Java"; yields "HelloJava" as the value of s. ii) String s = "Hello"; String s2= "Java"; s.concat( s2 ); After all the above 3 statements executed, s still refer to the value "Hello". s.concat(s2) does not change the s's value, but return new String object whose value is "HelloJava" Bala.
Joined: Dec 17, 2000
Hi Pratiti, The '+' operator is inherently overloaded by Java for String objects. Also the Java API defines a concat method for String objects which concatenates the specified string to the end of the first string. The effect of both these is bound to be the same. I guess because the overloaded '+' operator implicitly calls the concat() method of String objects. So you can use either of these, as long as you are comfprtable with it. Please correct me if I am wrong. Cheers Kapil
Hope this helps. Correct me if I am wrong.<p>Cheers <img src="smile.gif" border="0"> ,<br />Kapil