【发布时间】:2013-12-19 07:09:46
【问题描述】:
StringBuilder builder = new StringBuilder();
builder.setLength(10);
builder.append("d");
System.out.println(builder.length() + "\t" + builder.toString() + "\t" + builder.indexOf("d"));
输出:
11
问题:
Why indexOf() doesn't return anything.
我的理解:
As per my understanding, it should return 10, since StringBuilder is counting the "d" as part of its length in length().
But in case if "d" is not part of string hold by StringBuilder then, it should return -1 and length should be 10.
【问题讨论】:
标签: java string stringbuilder indexof