[java]代码库
/**
* 添加各种类型的数据到字符串尾部
*/
public static void testAppend() {
StringBuffer sb = new StringBuffer("This is a StringBuffer!");
// 添加字符或者字符数组到StringBuffer末尾
sb.append('I');
sb.append(new char[] { ' ', 'a', 'm' });
System.out.println("Append char: " + sb.toString());
// 添加字符串到StringBuffer末尾
sb.append(" in 、Beijing.");
System.out.println("Append String: " + sb.toString());
// 添加基本数字
sb.append(15);
sb.append(1.23f);
sb.append(3.4d);
sb.append(899L);
System.out.println("Append number: " + sb.toString());
// 添加布尔值
sb.append(false);
sb.append(true);
System.out.println("Append boolean: " + sb.toString());
}