提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用append方法将值添加到StringBuffer
public class Main {//NowJava.com - 时代Java 提 供 public static void main(String[] args) { //StringBuffer append(boolean b) method boolean b = true; StringBuffer sb1 = new StringBuffer("BooelanAppended : "); sb1.append(b); System.out.println(sb1); //StringBuffer append(char c) method char c = 'Y'; StringBuffer sb2 = new StringBuffer("CharAppended : "); sb2.append(c); System.out.println(sb2); /*StringBuffer append(char[] c) method to StringBuffer object*/ char[] c1 = new char[] {'Y','e','s'}; StringBuffer sb3 = new StringBuffer("Character Array Appended : "); sb3.append(c1); System.out.println(sb3);/**来 自 N o w J a v a . c o m**/ //StringBuffer append(double d) method double d = 1.0; StringBuffer sb4 = new StringBuffer("doubleAppended : "); sb4.append(d); System.out.println(sb4); //StringBuffer append(float f) method float f = 1.0f; StringBuffer sb5 = new StringBuffer("floatAppended : "); sb5.append(f); System.out.println(sb5); //StringBuffer append(int i) method int i = 1; StringBuffer sb6 = new StringBuffer("integerAppended : "); sb6.append(i); System.out.println(sb6); //StringBuffer append(long l) method long l = 1; StringBuffer sb7 = new StringBuffer("longAppended : "); sb7.append(l); System.out.println(sb7); //StringBuffer append(Object o) method /* NOTE : Objects are first converted to a String and then it is appended to StrinBuffer */ Object obj = new String("Yes"); StringBuffer sb8 =