我对以下代码感到困惑,因为我认为数组的长度(allCommands
)在没有任何内容时会为0。Java:为什么数组的长度为1时什么都没有了
字符串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: []
有人可以解释这一点吗?谢谢!
里面有东西 - 它是一个零长度的字符串。 –