Last active
January 5, 2019 15:19
-
-
Save RashidJorvee/17e92f0040b28388e7e37f9981a376fe to your computer and use it in GitHub Desktop.
How to use trimToSize() method in Java?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rashid.jorvee; | |
public class TrimToSize { | |
public static void main(String[] args) { | |
StringBuffer copyText=new StringBuffer(); | |
copyText.append("trim to size method in java"); | |
System.out.println(copyText +", and length of StringBuffer copyText is:" +copyText.length()); | |
System.out.println("Capacity of copyText is::"+copyText.capacity()); | |
copyText.trimToSize(); | |
System.out.println(copyText +", and length of StringBuffer copyText after trimToSize() is:" +copyText.length()); | |
System.out.println("Capacity of copyText after trimToSize() is::"+copyText.capacity()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output of this program: