You are here: Home / Topics / capacity() method example in Java

capacity() method example in Java

Filed under: Java on 2023-08-23 18:56:04

// Program to explain the following StringBuffer function :
// int capacity()

class  Mcapacity
{
public static void main( String args[ ] )
{
 StringBuffer sb1 = new StringBuffer();
 StringBuffer sb2 = new StringBuffer( "Java Programming Examples" );

 System.out.println( " Capacity = " + sb1.capacity() );
 System.out.println( " Capacity = " + sb2.capacity() );  
}
}


output:

Capacity = 16
Capacity = 41

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.