Posted on 1999-06-29
Ok. In the StringBuffer class we can use the method ensureCapacity() like this:
StringBuffer Str = new StringBuffer ("ABCDEFGH");
which will allocate the capacity as 8+16 = 24 unicodes.
Now when you say:
does not gurantee that the capacity would be 35 unicodes. First it will see if 35 or the (current capacity * 2)+2=
24 * 2 + 2 = 50 is the largest and sets to the largest between the two. Therefore in this case the capacity will be 50. Now my question is.... does anyone know why it adds extra 2 unicodes? For examples ... why (current-capacity *2) - which I understand... but why + 2 ?