欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

StringBuffer操作

程序员文章站 2022-04-18 09:32:46
...
package dao;

public class Strbuff {
public static void main(String[] args)
{
StringBuffer sb1 = new StringBuffer();
System.out.println(sb1.capacity());
System.out.println(sb1.length());
System.out.println();

StringBuffer sb2 = new StringBuffer(100);
System.out.println(sb2.capacity());
sb2.ensureCapacity(400);
System.out.println(sb2.capacity());
System.out.println();
System.out.println(sb2.length());

StringBuffer sb3 = new StringBuffer("my english is ");
sb3.append("revy good!");
System.out.println(sb3);

StringBuffer sb4 = new StringBuffer("my english is ");
sb4.append("revy good!");
sb4.setLength(10);
System.out.println(sb4);

StringBuffer sb5 = new StringBuffer("my english is ");
sb5.append("revy good!");
sb5.setCharAt(0,'M');
System.out.println(sb5);

StringBuffer sb6 = new StringBuffer("my english is ");
sb6.append("revy good!");
sb6.insert(0,"congratuions !");
System.out.println(sb6);

StringBuffer sb7 = new StringBuffer("my english is ");
sb7.append("revy good!");
System.out.println(sb7.substring(10));
System.out.println(sb7.substring(10,15));
System.out.println(sb7.reverse());


}
}


结果:
16
0

100
400

0
my english is revy good!
my english
My english is revy good!
congratuions !my english is revy good!
is revy good!
is r
!doog yver si hsilgne ym
相关标签: DAO