consider the following example : String str1 = new String ("chunky"); String str2 = str1 ; str1 = str1 + " shah " // a new string object str1 is created here if (str1 == str2 ) System.out.println("refers the same object ");//NO if (str1.equals(str2) System.out.println("has the same contents) ;//NO //i.e once a string object is modified an altogether new String object refers to it (String objects are immutable) //here s an example of string buffer StringBuffer str3 = new StringBuffer("chunky"); StringBuffer str4 = str3; //both now point to the same object str3.insert(6 ,"shah"); //str3 still refers to the same object even on modification if (str3 == str4 ) System.out.println("refers the same object ");//YES //i.e StringBuffer objects on modification too refer to the same old object hope this is clear enuf regards arawin
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, that will fit in a stocking