标签:源码 cli ima stat nbsp trim static sys release
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()); //区间表示[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(); //区间表示[0,sb.length) //trimToSize 整理一下空间 System.out.println(sb); System.out.println(sb.length()); System.out.println(sb.capacity()); } }
result:
Java优秀,值得学习。
学习资源:API手册+Java源码+清净的心地。
JavaSE8基础 StringBuffer delete trimToSize 清空字符串缓冲区与整理缓冲区的空间
标签:源码 cli ima stat nbsp trim static sys release
原文地址:http://www.cnblogs.com/jizuiku/p/7469540.html