【发布时间】:2016-11-21 20:57:38
【问题描述】:
我对我编写的以下代码感到困惑,因为我认为数组的长度 (allCommands) 会在其中没有任何内容时为 0。
字符串test 里面只有井号,然后我得到它后面的子字符串,然后用# 分割。
String test = "#";
int beginIndex = test.indexOf("#");
test = test.substring(beginIndex+1);
String[] allCommands = test.split("#");
System.out.println("allCommands length: " + allCommands.length); // output: 1
System.out.println("allCommands array: " + Arrays.toString(allCommands)); // output: []
有人能解释一下吗?谢谢!
【问题讨论】:
-
里面有东西——它是一个零长度的字符串。