Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show some properties of StringBuffer object

Posted By: Ashley Smith     Category: Java     Views: 2951

A Java Program to show some properties of StringBuffer object.

Code for Program to show some properties of StringBuffer object in Java

publicclass JAVA_057
 {


    publicstaticvoid 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( ));
    }
 }
  
Share: 


Didn't find what you were looking for? Find more on Program to show some properties of StringBuffer object Or get search suggestion and latest updates.

Ashley Smith
Ashley Smith author of Program to show some properties of StringBuffer object is from Sydney, Australia.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!