我对下面编写的代码感到困惑,因为我认为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: []
有人可以解释吗?谢谢!
它是一个零长度(空)的字符串,在程序下面显示0。
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[0].length());
System.out.println("allCommands array: " + Arrays.toString(allCommands));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句