Java.lang.StringBuffer.trimToSize() Method
Advertisements
Description
The java.lang.StringBuffer.trimToSize() method 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.
Declaration
Following is the declaration for java.lang.StringBuffer.trimToSize() method
public void trimToSize()
Parameters
NA
Return Value
This method does not return any value.
Exception
NA
Example
The following example shows the usage of java.lang.StringBuffer.trimToSize() method.
package com.tutorialspoint;
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("This is ");
// append the string to StringBuffer
buff.append("Java Lang Package");
// trimToSize buffer
buff.trimToSize();
System.out.println("Programming :" + buff);
}
}
Let us compile and run the above program, this will produce the following result:
Programming :This is Java Lang Package