你的word = new StringBuffer('P'); 初始化错了!应该写成word = new StringBuffer(“P”); 要双引号!
StringBuffer 的构造方法一共四种
第一个是 public StringBuffer():Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
第二种是public StringBuffer(int capacity):Constructs a string buffer with no characters in it and the specified initial capacity.
第三种是 public StringBuffer(String str):Constructs a string buffer initialized to the contents of the specified string. The initial capacity of the string buffer is 16 plus the length of the string argument.
第四种是 public StringBuffer(CharSequence seq):Constructs a string buffer that contains the same characters as the specified CharSequence. The initial capacity of the string buffer is 16 plus the length of the CharSequence argument.
If the length of the specified CharSequence is less than or equal to zero, then an empty buffer of capacity 16 is returned.
CharSequence seq 是一个接口 实现类为CharBuffer, Segment, String, StringBuffer, StringBuilder
|