Os:windows7 x64
Jdk:jdk-8u131-windows-x64
Ide:eclipse Oxygen Release (4.7.0)
Code
package Jizuiku1;public class Demo100 {public static void main (string[] args) { StringBuffer sb = new StringBuffer (); Sb.append ("Cnblog"); System.out.println (SB); System.out.println (Sb.length ()); System.out.println (Sb.capacity ()); System.out.println ("------------------"); Sb.append ("Jizuiku Jizuiku"); System.out.println (SB); System.out.println (Sb.length ()); System.out.println (Sb.capacity ()); System.out.println ("------------------"); Sb.delete (0, Sb.length ()); Interval expression [0,sb.length] System.out.println (SB); System.out.println (Sb.length ()); System.out.println (Sb.capacity ()); System.out.println ("------------------"); Sb.append ("Cnblog jizuiku Jizuiku"); System.out.println (SB); System.out.println (Sb.length ()); System.out.println (Sb.capacity ()); System.out.println ("------------------"); Sb.delete (0, Sb.length ()). TrimToSize (); Interval representation [0,sb.length]//trimtosize tidy up the Space System.out.println (SB); System.out.println (Sb.length ()); System.out.println (Sb.capacity ());}}
Result
Java is good, worth learning.
Learning Resources: API manual +java Source + pure heart.
JavaSE8 base StringBuffer Delete trimtosize Empty the space of the string buffer and the collation buffer