FastStringBuilder 

  快速的StringBuilder工具类。

public int length() 

  获得FastStringBuiler中存储的字符的个数。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append("zhangsan");

System.out.println(fsb.length());  //length:8

  

public FastStringBuilder append(char c) 

  向FastStringBuilder中添加字符。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append('C');

  

public FastStringBuilder append(char[] cs) 

  向FastStringBuider中添加字符数组。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

char c[] = "hello".toCharArray();

fsb.append(c);

  

public FastStringBuilder append(char[] cs, int offset, int length) 

  向FastStringBuider中添加字符数组的一部分。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

char c[] = {'A','B','C','D'};

fsb.append(c,0,4);  

//此方法有问题。

  

public FastStringBuilder append(String s, int offset, int length) 

  将字符串的一部分添加到FastStringBuilder中。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

String str = "hello world";

fsb.append(str,6,5);

System.out.println(fsb.toString());

  

public FastStringBuilder append(int i)s

  向FastStringBuilder中添加数字。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append(-5);

  

public FastStringBuilder append(long i) 

  向FastStringBuilder中添加数字。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append(999999999); 

  

public FastStringBuilder append(String str) 

  向FastStringBuilder中添加字符串。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append("hello");

  

public FastStringBuilder append(Object obj)

  向FastStringBuilder中添加对象。

代码实例

public class UtilTest {

   @Test

   public void testGetFormat(){

     FastStringBuilder fsb = new FastStringBuilder();

     fsb.append(new User("zhang",22));

     System.out.println(fsb.toString());

   }

}

 

class User {

   String name;

   int age ;

  

   public User(String name,int age){

     this.name = name;

     this.age = age;

   }

  

   public String toString(){

     return this.name + ", " + this.age;

   }

}

  

public void clear() 

  将FastStringBuildercount属性的值置为0

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append("hello");

fsb.clear();

  

public String toString() 

       FastStringBuilder中的内容转换为字符串形式。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append(new char[]{'A','B'});

String str = fsb.toString();

System.out.println(str);  //AB

  

public String toStringAndClose() 

  将FastStringBuilder中的内容转换为字符串形式并关闭缓冲区。

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append(new char[]{'A','B'});

String str = fsb.toStringAndClose();

System.out.println(str);

  

public void close() 

  关闭FastStringBuilder

代码实例

FastStringBuilder fsb = new FastStringBuilder();

fsb.append(new char[]{'A','B'});

fsb.close();