常用方法:
- 增append
- 删delete(start,end)
- 改replace(start,end,string)//将start——end间的内容替换掉,不含end
- 查indexOf //查找子串在字符串第1次出现的索引,如果找不到返回-1
- 插insert
- 获取长度 length ```java package test;
public class Main { public static void main(String[] args) { StringBuffer s = new StringBuffer(“hello”); //增 s.append(‘,’);// “hello,” s.append(“张三丰”);//“hello,张三丰” s.append(“赵敏”).append(100).append(true).append(10.5);//“hello,张三丰赵敏100true10.5” System.out.println(s);//“hello,张三丰赵敏100true10.5”
//删/** 删除索引为>=start && <end 处的字符* 解读: 删除 11~14的字符 [11, 14)*/s.delete(11, 14);System.out.println(s);//"hello,张三丰赵敏true10.5"//改//使用 周芷若 替换 索引9-11的字符 [9,11)s.replace(9, 11, "周芷若");System.out.println(s);//"hello,张三丰周芷若true10.5"//查找指定的子串在字符串第一次出现的索引,如果找不到返回-1int indexOf = s.indexOf("张三丰");System.out.println(indexOf);//6//插//在索引为9的位置插入 "赵敏",原来索引为9的内容自动后移s.insert(9, "赵敏");System.out.println(s);//"hello,张三丰赵敏周芷若true10.5"//长度System.out.println(s.length());//22System.out.println(s);}
}
```

