求教,为何得到的ddlist数据是[602, 3]中间为何为有个空格
String dd="602,3";
String[] ddlist=dd.split(",");
请问有何处理方式ddlist中的空格?谢谢!
在AbstractCollection类中,发现了toString方法。来看看AbstractCollection中的toString的实现
public String toString() {
Iterator it = iterator();
if (! it.hasNext())
return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
E e = it.next();
sb.append(e == this ? "(this Collection)" : e);
if (! it.hasNext())
return sb.append(']').toString();
sb.append(',').append(' ');
}
}
从代码中,我们确实可以看到,在toString方法中有一个.append(‘ ‘)来拼接了一个空格字符进去。所以我们在使用list.toString()方法的时候,出现了空格。