class
string {
public static void main(String[] args) {
String str1="str";
str1.concat("str1"); //Line 0
System.out.println(str1); // Line 1
System.out.println(str1.concat("str1"));//Line 2
}
}
Output -
str
strstr1
Please explain me the output. I know that Strings are immutable and will create a new String at Line0 but wouldn't the same thing happen at Line2.
Will be really obliged if somebody could explain it.
Thanks in Advance,
Ira