5 Replies Latest reply on Jul 16, 2007 1:53 PM by 807600

    different Result From String and String Buffer

      I am getting differnet result for String and StringBuffer case.
      public class NewClass {
              public static void main(String arg[]){
                      StringBuffer sb1 = new StringBuffer("A");
                      StringBuffer sb2 = new StringBuffer("B");
                      System.out.println("sb1 : "+sb1+" sb2 : "+sb2);//O/P is sb1 : AB sb2: B
                      String s1 = new String("A");
                      String s2 = new String("B");
                      System.out.println("s1 : "+s1+" s2 : "+s2);O/P is s1 : A s2: B
           private static void operate(StringBuffer x, StringBuffer y) {
                      y = x;
              private static void operateString(String x, String y) {
                      y = x;
      while i call append method of StringBuffer what is happening internally?
      I wants to know like what happened to the Content of StringBuffer sb1, how it is changing from A to AB.
      Pls. guide me to understand this point