String s1 = "Sk";
s1.concat(" Y");
System.out.println("s1 refers to "+s1);
The above code generates the output "Sk" and not "Sk Y". I hope I'm explaining clear enough.Why is this ?
String s1 = "Sk";
s1.concat(" Y");
System.out.println("s1 refers to "+s1);
The above code generates the output "Sk" and not "Sk Y". I hope I'm explaining clear enough.Why is this ?
s1.concat(" Y");
doesn't alter s1
(it can't, since Strings are immutable).
It returns a new String :
String s2 = s1.concat(" Y");
System.out.println("s2 refers to "+s2);