In the above code I expect the value being chaged in the methods m1 and m2 is local StringBuffres .but the result is different . can any one help me out where I am goig wrong..... [ February 04, 2006: Message edited by: manogna edintipal ]
String object is immutable. Once you have assigned a String value that value can never change. for Ex: String s = new String("Infosys"); System.out.println(s); // Infosys s.concat(Technologies"); // it creates the temporary new String object and appens the value and it will not add to Original String System.out.println(s); // Infosys System.out.println(s.concat(Technologies")); //Infosys Technologies(Temporary string will displayed)
Because of this problems only Sun as introduced the StringBuffer concepts