2 Replies Latest reply: Dec 30, 2008 8:55 PM by 807589 RSS

    StringBuffer array Problem

    807589
      I am creating a StringBuffer array but strangely, when I append some string into one element fo array, it is appended into all elements of the array. Am I doing something wrong?
      StringBuffer emptyBuf = new StringBuffer("");
      StringBuffer SB[] = new StringBuffer[2];
      SB[0] = emptyBuf;
      SB[1] = emptyBF;
      
      SB{0].append("xxx");
      SB[1].append("yyy");
      
      System.out.print(SB[0].toString());
      System.out.print(SB[1].toString());
      
      OUTPUT: xxxyyy xxxyyy (i.e., same for both elements)