package String;
public class Demo1 {
public static void main(String[] args) {
//StringBuffer StringBuilder
//1.创建
StringBuffer stringBuffer=new StringBuffer("Hello world");
StringBuffer stringBuffer1=new StringBuffer();
//方法
//1.append():在末尾添加
System.out.println("1.append():在末尾添加:");
StringBuffer stringBuffer2=new StringBuffer();
stringBuffer2.append("123");
System.out.println(stringBuffer2);
System.out.println("===");
//2.insert(int index,String s):在指定位置插入string
System.out.println("2.insert(int index,String s):在指定位置插入string:");
StringBuffer stringBuffer3=new StringBuffer("abc");
stringBuffer3.insert(1,"123");
System.out.println(stringBuffer3);
System.out.println("===");
//3.toString:返回为字符串对象
System.out.println("3.toString:返回为字符串对象:");
StringBuffer stringBuffer4=new StringBuffer("Hello123");
String s=stringBuffer.toString();
System.out.println(s);
System.out.println("===");
//4.reverse():字符串反转
System.out.println("4.reverse():字符串反转:");
StringBuffer stringBuffer5=new StringBuffer("Hello123");
stringBuffer5.reverse();
System.out.println(stringBuffer5);
System.out.println("===");
//5.deleteCharAt(int index):删除指定位置的字符
System.out.println("5.deleteCharAt(int index):删除指定位置的字符:");
StringBuffer stringBuffer6=new StringBuffer("123456H");
stringBuffer6.deleteCharAt(0);
System.out.println(stringBuffer6);
System.out.println("===");
//6.delete(int start,int end):删除指定范围的字符串
System.out.println("6.delete(int start,int end):删除指定范围的字符串:");
StringBuffer stringBuffer7=new StringBuffer("123456F");
stringBuffer7.delete(0,1);//[start,end)
System.out.println(stringBuffer7);
System.out.println("===");
//7.replace(int start,int end,String):替换
System.out.println("7.replace(int start,int end,String):");
StringBuffer stringBuffer8=new StringBuffer("Hello World");
stringBuffer8.replace(0,stringBuffer8.length(),"999");//[start,end]
System.out.println(stringBuffer8);
System.out.println("===");
//8.setCharAt(int index,char c):修改
System.out.println("8.setCharAt(int index,char c):修改:");
StringBuffer stringBuffer9=new StringBuffer("12345F");
stringBuffer9.setCharAt(0,'0');
System.out.println(stringBuffer9);
System.out.println("===");
}
}
1.append():在末尾添加:
123
===
2.insert(int index,String s):在指定位置插入string:
a123bc
===
3.toString:返回为字符串对象:
Hello world
===
4.reverse():字符串反转:
321olleH
===
5.deleteCharAt(int index):删除指定位置的字符:
23456H
===
6.delete(int start,int end):删除指定范围的字符串:
23456F
===
7.replace(int start,int end,String):
999
===
8.setCharAt(int index,char c):修改:
02345F
===Process finished with exit code 0