package test1;
public class A {
//用append连接字符串
public static void main(String[] args)
{
StringBuffer buf1=new StringBuffer();
buf1.append("hello ");
buf1.append(" ").append("world").append("!!!");
String str=buf1.toString(); //将StringBuffer变成String
System.out.println(buf1);
System.out.println(str.indexOf("hello")); //已经转换了 返回0
for(int i=0;i<100;i++)
{
buf1.append(i);
}
System.out.println(buf1);
//常用Stringbuffer
//在指定位置添加 使用insert方法
StringBuffer buf2=new StringBuffer();
buf2.append("hello world ");
buf2.insert(1, "majianjie");
buf2.insert(0, "mjj");
System.out.println(buf2);
//删除指定范围的内容
buf2.delete(0, 9);
System.out.println(buf2);
//内容反转
buf2.replace(0, buf2.length(), "majianjie");
System.out.println(buf2);
StringBuffer str2=buf2.reverse();
System.out.println(str2);
}
}