Return | Method | Summary |
---|---|---|
int | capacity() | Returns the current capacity. |
int | length() | Returns the length (character count). |
void | ensureCapacity(int minimumCapacity) | Ensures that the capacity is at least equal to the specified minimum. |
void | setLength(int newLength) | Sets the length of the character sequence. |
void | trimToSize() | Attempts to reduce storage used for the character sequence. |
public class Main {
public static void main(String[] argv) {
StringBuilder sb = new StringBuilder();
sb.append("java2s.com");
System.out.println(sb.length());
System.out.println(sb.capacity());
sb.trimToSize();
System.out.println(sb.length());
System.out.println(sb.capacity());
}
}
The output:
10
16
10
10
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |