参照String源代码2250-2252行 (jdk1.8.0_171)
If the expression does not match any part of the input then the resulting array has just one element, namely this string.
如果没有匹配到任何字符,则返回他自己。
空字符串属于上面的情况。
参照String源代码2363,2364行 (jdk1.8.0_171)
if (off == 0)
return new String[]{this};
第二个参数limit默认值为0,意思是match后的所有空字符串,但这属于没有match的情况,命中了上面的case,所以返回自己,长度为1的空字符串。
有人提交过JDK的BUG,被认为不是BUG,参照如下:
参照:https://bugs.openjdk.java.net/browse/JDK-8020672
This is not a bug. The spec states that:
If the expression does not match any part of the input then the resulting array has just one element, namely this string.
In this case " ".split( " , " , 0) - there is no matching pattern and thus it returns the original string " ".