/*
A:StringBuffer的替换功能
public StringBuffer replace(int start,int end,String str): 从start开始到end用str替换
B:StringBuffer的反转功能
public StringBuffer reverse(): 字符串反转
C:案例演示
StringBuffer的替换和反转功能
*/
public class StringBufferDemo4 {
public static void main(String[] args) {
fun1();
StringBuffer sb = new StringBuffer("abcdefg");
sb.reverse();
System.out.println(sb);
sb.toString();
}
private static void fun1() {
// 字符串缓冲区
StringBuffer sb = new StringBuffer("javahello");
sb.replace(1, 4, "xxxxxxx");
System.out.println(sb);
StringBuffer replace = new StringBuffer("188234985798").replace(3, 500,
"xxxxxxxxx");
System.out.println(replace);
}
}
|
|