StringBuilder bu = new StringBuilder(); StringBuilder bu2 = new StringBuilder(); StringBuilder bu4 = bu.append("cbd"); StringBuilder bu3 = bu.append("cbd"); bu.append(true); System.out.println(bu); System.out.println(bu2); String s = bu.toString(); public static void main(String[] args) { // 构建StringBuilder对象 StringBuilder bu = new StringBuilder();// "" 0 // 调用insert方法 【System.out.println(bu.length());】 /* if ((offset < 0) || (offset > length())) throw new StringIndexOutOfBoundsException(offset); */ 【StringBuilder bu2 = bu.insert(0, "A");】 System.out.println(bu2); System.out.println(bu == bu2); System.out.println(bu2.length()); bu.insert(1, "B"); System.out.println("bu2:" + bu2); // 插入一个布尔类型值 bu.insert(2, true); System.out.println(bu); System.out.println("bu字符串缓冲区的长度为:" + bu.length()); System.out.println("bu字符串缓冲区的容量大小为:" + bu.capacity()); Student student = new Student(); student.setAge(10); student.setName("小王"); bu.insert(6, student); System.out.println("="); System.out.println(bu.length()); System.out.println(bu); System.out.println("="); 【System.out.println(bu.capacity());// miniCapacity.lenght()】Integer.MAX_VALUE < minCapacity // throw
浙公网安备 33010602011771号