Click here to watch in Youtube :
https://www.youtube.com/watch?v=uZGEbNwLv8c&list=UUhwKlOVR041tngjerWxVccw&nohtml5=False
/* * public 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. Calling * this method may, but is not required to, affect the * value returned by a subsequent call to the capacity() * method. */ public class StringBufferDemo { public static void main(String[] args) { StringBuffer sb = new StringBuffer("Welcome"); System.out.println("Before timeToSize,Length = " + sb.length()); System.out.println("Before timeToSize,Capacity = " + sb.capacity()); sb.trimToSize(); System.out.println("After timeToSize,Length = " + sb.length()); System.out.println("After timeToSize,Capacity = " + sb.capacity()); } }
Before timeToSize,Length = 7 Before timeToSize,Capacity = 23 After timeToSize,Length = 7 After timeToSize,Capacity = 7
https://sites.google.com/site/javaee4321/java/StringBufferDemo_trimToSize_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringBufferDemo_trimToSize_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b619d82bc2ef649a34c8b32345e1c58e65ad78f7/BasicJava/StringBufferDemo_trimToSize_App/?at=master
See also:
No comments:
Post a Comment