public class Test{
public static void main(String args[]){
//StringBuffer类主要方法:append reverse insert
StringBuffer sBuffer = new StringBuffer("融水公子很帅:");
sBuffer.append("www");//后添加 public StringBuffer append(String s)
sBuffer.append(".123");
sBuffer.append(".com");
System.out.println(sBuffer);
sBuffer.reverse();//取反 public StringBuffer reverse()
System.out.println(sBuffer);
sBuffer.delete(0,2);//删除下标0,1 public delete(int start, int end)
System.out.println(sBuffer);
sBuffer.insert(0,9);//下标0 插入数字9 public insert(int offset, int i)
System.out.println(sBuffer);
sBuffer.replace(0,2,"woaini");//代替0,1 replace(int start, int end, String str)
System.out.println(sBuffer);
}
}
public class Test{
public static void main(String args[]){
StringBuffer sBuffer = new StringBuffer("融水公子不愧是千古奇才:");
sBuffer.append("www");
sBuffer.append(".哪里哪里");
sBuffer.append(".com");
System.out.println(sBuffer);//输出
System.out.println(sBuffer.capacity());//返回当前容量28 int capacity()
System.out.println(sBuffer.charAt(0)); //返回下标0 的值 char charAt(int index)
sBuffer.ensureCapacity(30);//确保容量 void ensureCapacity(int minimumCapacity)
//当前容量小于参数 容量重新分配 重新分配的容量是旧容量的两倍 28<30
System.out.println(sBuffer.capacity());//-->28*2+2=58
char[] mubiao1=new char[40];
char[] mubiao2={'z','y','j','z','d','h','s'};
sBuffer.getChars(0,4,mubiao1,0); // 复制到目标字符数组 dst
sBuffer.getChars(0,4,mubiao2,0); // 复制到目标字符数组 dst
//oid getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
System.out.println(mubiao1);//融水公子
System.out.println(mubiao2);//融水公子dhs
}
}