/
StringBuffer的常用方法:
1.StringBuffer append(xxx):提供了很多append()方法,用于进行字符串拼接
2.StringBuffer delete(int start,int end):删除指定位置的内容
3.StringBuffer replace(int start,int end,String str):把[start,end)位置替换为str
4.StringBuffer insert(int offset,xxx):在指定位置插入xxx
5.StringBuffer reverse():把当前字符序列逆转
6.public int indexOf(String str)
7.public String substring(int start,int end):返回一个从start开始到end索引结束的左闭右开
区间的子字符串
8.public int length()
9.public char charAt(int n)
10.public void setCharAt(int n,char ch)
总结: (必会的方法)
增:append(xxx)
删:delete(int start,int end)
改:setCharAt(int n,char ch) / replace(int start,int end,String str)
查:charAt(int n)
插:insert()
长度:length()
遍历:for + charAt() / toSting()
*/
/*
StringBuffer的常用方法:
1.StringBuffer append(xxx):提供了很多append()方法,用于进行字符串拼接
2.StringBuffer delete(int start,int end):删除指定位置的内容
3.StringBuffer replace(int start,int end,String str):把[start,end)位置替换为str
4.StringBuffer insert(int offset,xxx):在指定位置插入xxx
5.StringBuffer reverse():把当前字符序列逆转
6.public int indexOf(String str)
7.public String substring(int start,int end):返回一个从start开始到end索引结束的左闭右开
区间的子字符串
8.public int length()
9.public char charAt(int n)
10.public void setCharAt(int n,char ch)
总结:
增:append(xxx)
删:delete(int start,int end)
改:setCharAt(int n,char ch) / replace(int start,int end,String str)
查:charAt(int n)
插:insert()
长度:length()
*遍历:for + charAt() / toSting()
*/
@Test
public void test2(){
StringBuffer s1 = new StringBuffer("abcde");
//1.
s1.append(1);
s1.append('1');
System.out.println(s1);
//2.
s1.delete(2,4);
System.out.println(s1);
//3.
s1.replace(0,3,"h");
System.out.println(s1);
//4.
s1.insert(1,"work");
System.out.println(s1);
//5.
System.out.println(s1.reverse());
System.out.println("********6 ***查");
//6.查
System.out.println(s1.charAt(4));
//7.
System.out.println(s1.substring(1,4));
//10.
s1.setCharAt(1,'x');
System.out.println(s1);
}