StringBuffer:
length() and capacity()
The length of the StringBuffer can be found by the length() method.while the total capacity can be found through the capacity() method.They have the following forms:
int length();
int capacity();
package stringdemo;
public class LengthAndCapacity {
public static void main(String[] args) {
StringBuffer s= new StringBuffer("Dance");
System.out.println("Length="+s.length());
System.out.println("Capacity"+s.capacity());
}
}
OUTPUT:
Length=5
Capacity21
Here Length is 5 and capacity is 21 because room for 16 additional characters is automatically added,so result is 21.
Here Length is 5 and capacity is 21 because room for 16 additional characters is automatically added,so result is 21.
0 comments:
Post a Comment