I have made following code.The first statement gives me output 21.
That is i know that default capacity is 16 + 5 for Hello
But i don't get, why it gives 44 as output as i am increasing capacity from 21 to 30 by using ensurecapacity() method.
StringBuffer sb = new StringBuffer("hello");
System.out.println(sb.capacity());//output 21
sb.ensureCapacity(30);
System.out.println(sb.capacity());//output 44
is it the thing that we have to use ensurecapacity() method only when we have created instance of this class with constructor
StringBuffer sb = new StringBuffer(5);
can anyone give me proper justification on it?