为什么写这篇博客??
在字符串处理过程中经常会用到split函数将字符串分割成字符串数组。但是因为这个东西拿过来直接用就行很方便,但是经常出错因为不知道细节往往不好查错。于是乎今天好好读了这个源码,想把自己的理解分享一下同时有些没大看懂的地方需要高人指点。
先上源码:
public String[] split(String regex, int limit) {
/* fastpath if the regex is a
(1)one-char String and this character is not one of the
RegEx's meta characters ".$|()[{^?*+\\", or
(2)two-char String and the first char is the backslash and
the second is not the ascii digit or ascii letter.
*/
char ch = 0;
if (((regex.value.length == 1 &&
".$|()[{^?*+\\".indexOf(ch = regex.charAt(0)) == -1) ||
(regex.le