//*****************************************************************************
// StringBuffer - Copy or Reference?                           
//*****************************************************************************

public class stringBuf2 
{
    public static void main(String[] args)
    {

        StringBuffer text1 = new StringBuffer ("this is some data");    //original StringBuffer
        StringBuffer text2 = text1;                                     //This is not a copy
        StringBuffer text3 = new StringBuffer(text1);                   //This is a copy

        System.out.println( text1 +"\n"+ text2 +"\n"+ text3 );
        System.out.println();
                                                              //output: //text1-> this is some data
                                                                        //text2-> this is some data
                                                                        //text3-> this is some data

        text1.append(", appended thru 'text1' ");                       //append to the original text

        System.out.println( text1 +"\n"+ text2 +"\n"+ text3 );
        System.out.println();
                                                              //output: //text1-> this is some data, appended thru 'text1'
                                                                        //text2-> this is some data, appended thru 'text1'
                                                                        //text3-> this is some data


        text2.append(", appended thru 'text2' ");                       //will also append to original text
        text3.append(", appended thru 'text3' ");                       //append to text3 - separate copy

        System.out.println( text1 +"\n"+ text2 +"\n"+ text3 );
        System.out.println();
                                                              //output: //text1-> this is some data, appended thru 'text1', appended thru 'text2'
                                                                        //text2-> this is some data, appended thru 'text1', appended thru 'text2'
                                                                        //text3-> this is some data, appended thru 'text3'
    }
}