Java的StringBuffer类 Li.034
String 与 StringBuffer 区别 StringBuffer 是线程安全的可变字符序列 String 是一个不可变的字符序列 StringBuffer 的构造函数 public class Demo1_Sb { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); System.out.println(sb.length()); System.out.println(sb.capacity()); StringBuffer sb2 = new StringBuffer(10); System.out.println(sb2.length()); System.out.println(sb2.capacity()); StringBuffer sb3 = new StringBuffer("hello"); System.out.println(sb3.length()); System.out.println(sb3.capacity()); } } StringBuffer 的append 和 insert 方法 StringBuffer append() 支持int String StringBuffer boolean, 返回本身, StringBuffer insert(int , String) 在指定索引添加int String char等, 返回本身, 有可能会越界 public class Demo2_Sb { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb....