string split()
String[] xwb_ids = "".split(":");
System.out.println(xwb_ids.length);
1
split后长度最小是1
*****************************
String[] xwb_ids = "abc".split(":");
System.out.println(xwb_ids.length);
1
***********************************
String[] xwb_ids = "abc:".split(":");
System.out.println(xwb_ids.length);
1
***********************************
String[] xwb_ids = "abc: ".split(":");
System.out.println(xwb_ids.length);
2
**********************************
String[] xwb_ids = "abc:bcd".split(":");
System.out.println(xwb_ids.length);
2
因为split性能不高,换成这个分割方法了
//delimiterChar分割字符的ascci,例如”:” 就写 58
//String[] xwb_ids = fastSplit(“abc: ”,(char)58);
public static String[] fastSplit(String str, char delimiterChar) {
int startPos = 0; int len = str.length(); String[] result = new String[len + 1];
int resultIndex = 0; for (int i = 0; i < len; i++) { if (str.charAt(i) == delimiterChar) { result[resultIndex] = str.substring(startPos, i); startPos = i + 1; resultIndex++; } }
result[resultIndex] = str.substring(startPos); return Arrays.copyOfRange(result, 0, resultIndex + 1); }