StringBuffer
时间:2011-01-22 来源:魔战
二,Demo2
public class StringBufferDemo2 {
public static void main(String args[])
{
StringBuffer buf=new StringBuffer();
fun(buf);
for(int i=0;i<1000;i++)
{
buf.append(i);
}
System.out.println(buf);
}
public static void fun(StringBuffer b)
{
b.append("hello world!!").append("\n");
}
}
三,Demo3
public class StringBufferDemo2 {
public static void main(String args[])
{
StringBuffer buf=new StringBuffer();
//添加字符串
buf.append("hello");
//在指定的位置插入字符串
buf.insert(0, " world");
buf.insert(1, " nihao!");
System.out.println(buf.toString());
//删除指定位置的字符串
buf.delete(1, 3);
System.out.println(buf.toString());
//替换字符串
buf.replace(0, 5, "hello");
System.out.println(buf.toString());
//字符串反转
buf.reverse();
System.out.println(buf.toString());
}
}