This code:
String s = "TEST";
String s2 = s.trim();
s.concat("ING");
System.out.println("S = "+s);
System.out.println("S2 = "+s2);
results in this output:
S = TEST
S2 = TEST
BUILD SUCCESSFUL (total time: 0 seconds)
Why are “TEST” and “ING” not concatenated together?
a String is immutable, meaning you cannot change a String in Java. concat() returns a new, concatenated, string.