使用split(regEx)
和split(regEx, 0)
有什么区别吗?
因为输出是针对我测试过的情况。例如:
String myS = this is stack overflow;
String[] mySA = myS.split(' ');
结果在 mySA === {'this','is','stack,'overflow'}
和
String myS = this is stack overflow;
String[] mySA = myS.split(' ', 0);
还会导致 mySA === {'this','is','stack,'overflow'}
这里有什么“隐藏”的事情吗?或者关于 .split(regEx, 0)
需要了解的其他内容?
最佳答案
它们本质上是一样的。
引自String.split(String regex)
文档:
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
关于 "split(regEx)"和 "split(regEx, 0)"之间的 Java 区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29603365/