Login Here                        

Immutability of String

        Objects are broadly classified as mutable and immutable objects. Mutable objects are those objects whose contents can be modified. Immutable objects are those objects, once created can not be modified. String class objects are immutable. Once string object is created its data or state can't be changed but a new string object is created. Let us take a program to understand whether the string objects are immutable or not

Java Images

Immutability of String

class Test
public static void main(String[] args)
String str1=new String("");
String str2=str1.concat("hi");

intput and output,,freetimestudy.comhi