Output is: abc def abcDEF Isn't "def".toUpperCase() same as s2.toUpperCase()? (if s2 contained "def") If both are the same, then the argument to s1.concat(), would be "DEF". If this is true then after the statement s1.concat(s2.toUpperCase()); is executed, s1 should contain "abcDEF". But according to the above code, this is false s1 contains "abc" after the statement s1.concat(s2.toUpperCase()); is executed. Can anybody explain the why s1 still contains "abc" even after the concat() function was called on the object s1? Kezia.
from the sun API http://java.sun.com/products/jdk/1.2/docs/api/index.html concat public String concat(String str) Concatenates the specified string to the end of this string. If the length of the argument string is 0, then this String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.
Parameters: str - the String that is concatenated to the end of this String. Returns: a string that represents the concatenation of this object's characters followed by the string argument's characters.