提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
StringBuilder方法charAt,setCharAt,getChars和reverse。
public class Main // 来 自 n o w j a v a . c o m { public static void main(String[] args) { StringBuilder buffer = new StringBuilder("hello there"); System.out.printf("buffer = %s\n", buffer.toString()); System.out.printf("Character at 0: %s\nCharacter at 4: %s\n\n", buffer.charAt(0), buffer.charAt(4)); char[] charArray = new char[buffer.length()]; buffer.getChars(0, buffer.length(), charArray, 0); System.out.print("The characters are: "); for (char character : charArray) System.out.print(character); buffer.setCharAt(0, 'H'); buffer.setCharAt(6, 'T'); System.out.printf(