public class Demo2_StringBuffer {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
System.out.println(sb.toString()); //StringBuffer重写了toString
StringBuffer sb1 = sb.append("你好"); //把任意类型的数据添加到字符串缓冲区
System.err.println(sb1);
StringBuffer sb2 = sb.append("吗?");
System.out.println(sb2);
System.out.println(sb2.toString());
sb.insert(4, ",我很好."); //从指定位置添加字符串
System.out.println(sb2);
sb.deleteCharAt(4); //根据索引删除掉字符
sb.delete(0,4); //根据区间删除字符串
System.out.println(sb2);
}
} |
|