How can you find the length and capacity of a string buffer

Showing Answers 1 - 1 of 1 Answers

Thamizhselvi

  • Jul 23rd, 2007
 

1.The current length of a StringBuffer can be found through length().

2.The total allocated capacity can be found via capacity().

Example:
class Demo
{
public static void main(String a[])
{
StringBuffer s=new StringBuffer("Welcome");
System.out.println(" Buffer Value : "+s);
System.out.println("Current Length : " +s.length());
System.out.println(" Allocated Capacity : "+s.capacity());
}
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions