Java StringBuilder trimToSize() method attempts to reduce storage used for the character sequence.
public class TrimToSizeExample {
public static void main(String[] args) {
StringBuilder builder = new StringBuilder("javaguides ");
System.out.println(builder.capacity());
builder.trimToSize();
System.out.println(builder.capacity());
}
}
Output:
27
11
Comments
Post a Comment