Why does Java’s concat() method not do anything?

a String is immutable, meaning you cannot change a String in Java. concat() returns a new, concatenated, string.

String s = "TEST";
String s2 = s.trim();
String s3 = s.concat("ING");

System.out.println("S = "+s);
System.out.println("S2 = "+s2);
System.out.println("S3 = "+s3);

Leave a Comment