1 import java.text.*;
2 public class Gxjun
3 {
4 public static void main(String atgs[])
5 {
6 StringBuffer str= new StringBuffer();
7 str.append("大家好");
8 System.out.println("str:"+str);
9 System.out.println("length:"+str.length());
10 System.out.println("capacity:"+str.capacity());
11 str.setCharAt(0,‘w‘);
12 str.setCharAt(1,‘e‘);
13 System.out.println(str);14 str.insert(2, "are all");
15 System.out.println(str);
16 int index=str.indexOf("好");
17 str.replace(index, str.length(),"right");
18 System.out.println(str);
19 }
20 }
初学java之StringBuffer类的常用方法
时间: 2024-10-06 19:59:12