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

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

The StringBuffer is a class that has a mutable sequence of characters.

 Length and capacity of the StringBuffer object can be find out by the following two methods: * length() * capacity()Capacity of the StringBuffer is always plus 16 to the length. Example:class StringBufferExample { public static void main(String args[]) { StringBuffer sb = new StringBuffer(\"Hello World!\"); 

 System.out.println(\"Buffer value= \"+sb); System.out.println(\"Length = \" +sb.length()); System.out.println(\"Capacity = \" +sb.capacity()); }}


By:Jalees
Date:2012-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher