Are all Strings immutable?

Value of a String Object once created cannot be modified. Any modification on a String object creates a new String object.

 

String str3 = "value1";
str3.concat("value2");
System.out.println(str3); //value1

Note that the value of str3 is not modified in the above example. The result should be assigned to a new reference variable (or same variable can be reused). All wrapper class instances are immutable too!

String concat = str3.concat("value2");
System.out.println(concat); //value1value2