StringBuffer s = new StringBuffer("hello");
// 增
s.append(","); // hello,
s.append("world").append(100).append(true); // hello,world100true
System.out.println(s);
// 删 [start,end) 索引
s.delete(2,5); //he,world100true
// 改 替换[start,end) 第三个参数为替换的字符串
s.replace(3,5,"123345"); //he,123345rld100true
System.out.println(s);
// 查 indexOf
System.out.println(s.indexOf("123")); // 3
// 插入 insert 在索引为1的位置插入what,原来的元素后移
s.insert(1,"what");
StringBuffer常用方法
于 2024-06-28 15:32:24 首次发布