提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
StringBuilder方法插入,删除和deleteCharAt。
public class Main { public static void main(String[] args) /** 来 自 N o w J a v a . c o m **/ { Object objectRef = "hello"; String string = "goodbye"; char[] charArray = {'a', 'b', 'c', 'd', 'e', 'f'}; boolean booleanValue = true; char characterValue = 'K'; int integerValue = 7; long longValue = 10000000; float floatValue = 2.5f; // f suffix indicates that 2.5 is a float double doubleValue = 33.333; StringBuilder buffer = new StringBuilder(); buffer.insert(0, objectRef) .insert(0, " ") // each of these contains new line .insert(0, string) .insert(0, " ")// 来 自 n o w j a v a . c o m - 时代Java .insert(0, charArray) .insert(0, " ") .insert(0, charArray, 3, 3) .insert(0, " ") .insert(0, booleanValue) .insert(0, " ") .insert(0, characterValue) .insert(0, " ") .insert(0, integerValue) .insert(0, " ") .insert(0, longValue) .insert(0, " ") .insert(0, floatValue) .insert(0, " ") .insert(0, doubleValue);