Hi Test This is the explanation of ensureCapacity public void ensureCapacity(int minimumCapacity) Ensures that the capacity of the buffer is at least equal to the specified minimum. If the current capacity of this string buffer is less than the argument, then a new internal buffer is allocated with greater capacity. The new capacity is the larger of: The minimumCapacity argument. Twice the old capacity, plus 2.
If the minimumCapacity argument is nonpositive, this method takes no action and simply returns. Parameters: minimumCapacity - the minimum desired capacity. When we apply that to your code, the current capacity being 16 whatever we give as minimumCapacity which is less than or equal to 16 the new capacity() return value will be 16 only. But when we give anything more than 16 to minimumCapacity then the capacity() return value will be that value. Thanks ARS Kumar.
ARS Kumar, Sun Certified Programmer for Java 2 Platform