62,625
社区成员
发帖
与我相关
我的任务
分享 StringBuilder sb = new StringBuilder("sdfsf");
char d = 'd';
System.out.println(d);
sb.insert(0, d); //报错行
System.out.println(sb);
package mi;
public class TTT
{
public static void main(String[] args)
{
StringBuilder sb = new StringBuilder("sdfsf");
char d = 'd';
System.out.println(d);
sb.insert(0, d);
System.out.println(sb);
}
}
看了一下8的API
StringBuilder insert(int offset, boolean b)
Inserts the string representation of the boolean argument into this sequence.
有这个方法,参数也没有问题。
你把代码 和 抛出的异常 粘全了,全部贴出来看看 /**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public StringBuilder insert(int offset, char c) {
super.insert(offset, c);
return this;
}