Thursday, 10 July 2014

trimToSize()

public synchronized void trimToSize()
Attempts to reduce storage used for the character sequence. If the buffer is larger than necessary to hold its current sequence of characters, then it may be resized to become more space efficient.

public class StringBufferTrimToSize {
    public static void main(String args[]){
        StringBuffer s = new StringBuffer("HI");
        
        System.out.println(s.capacity());
        s.trimToSize();
        System.out.println(s.capacity());
    }
}

Output
18
2



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment