Java Blog

 
 
 
 public class JAVA_057
 {


    public static void main(String[] args)
    {
       StringBuffer SB1=new StringBuffer(\"This is a StringBuffer Object!\");

       System.out.println(\"StringBuffer # 1 : \" + SB1);

       System.out.println(\"Length : \" + SB1.length( ));
       System.out.println(\"Capacity : \" + SB1.capacity( ));

       SB1.setLength(20);

       System.out.println(\"\\nStringBuffer # 1 : \" + SB1);
       System.out.println(\"Length : \" + SB1.length( ));
       System.out.println(\"Capacity : \" + SB1.capacity( ));

       StringBuffer SB2=new StringBuffer(15);

       System.out.println(\"\\nStringBuffer # 2 : \" + SB2);
       System.out.println(\"Length : \" + SB2.length( ));
       System.out.println(\"Capacity : \" + SB2.capacity( ));

       SB2=SB1;

       System.out.println(\"\\nStringBuffer # 2 : \" + SB2);
       System.out.println(\"Length : \" + SB2.length( ));
       System.out.println(\"Capacity : \" + SB2.capacity( ));

       SB2.ensureCapacity(50);

       System.out.println(\"\\nStringBuffer # 2 : \" + SB2);
       System.out.println(\"Length : \" + SB2.length( ));
       System.out.println(\"Capacity : \" + SB2.capacity( ));
    }
 }

 
 
Didn't find what you were looking for? Find more on Program to show some properties of StringBuffer object