package com.zongjie;
public class Demo4_StringBuffer {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("HEIMA");
sb.replace(0,3,"BAI"); //把某区间的字符串替换为指定的字符串
sb.reverse(); //StringBuffer的反转
System.out.println(sb);
String a = sb.substring(2); //截取索引后的字符串,返回值不是StringBuffer的本身,而是一个字符串,用String类型接收
System.out.println(a);
String b = sb.substring(1,3);//截取某区间的字符串
System.out.println(b);
}
}
|
|