public static String[] split(String s, String token) {
if (s == null)
return null;
if (token == null || s.length() == 0)
return new String[] { s };
int size = 0;
String[] result = new String[4];
while (s.length() > 0) {
int index = s.indexOf(token);
String splitOne = s;
if (index > -1) {
splitOne = s.substring(0, index);
s = s.substring(index + token.length());
} else {
s = "";
}
if (size >= result.length) {
String[] tmp = new String[result.length * 2];
System.arraycopy(result, 0, tmp, 0, result.length);
result = tmp;
}
if (splitOne.length() > 0) {
result[size++] = splitOne;
}
}
String[] tmp = result;
result = new String[size];
System.arraycopy(tmp, 0, result, 0, size);
return result;
}
测试过,这个确实比官方的分割方法速度快,原始作者不晓的是谁了,因为隔好久了,现在总结才找到的代码
