limit是正整数时表示分割成几个字串,先分割前面的
limit是负整数时表示完全分割,子串可能会是""
limit是0时,与split("分割符")同义,子串不会是""
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | String str = "a,b,c,,"; String[] strAry = str.split(","); System.out.print(strAry.length); System.out.println(Arrays.asList(strAry)); String[] strAry0 = str.split(",",0); System.out.print(strAry0.length); System.out.println(Arrays.asList(strAry0)); String[] strAry1 = str.split(",",1); System.out.print(strAry1.length); System.out.println(Arrays.asList(strAry1)); String[] strAry2 = str.split(",",2); System.out.print(strAry2.length); System.out.println(Arrays.asList(strAry2)); String[] strAry_1= str.split(",",-1); System.out.print(strAry_1.length); System.out.println(Arrays.asList(strAry_1)); String[] strAry_2 = str.split(",",-2); System.out.print(strAry_2.length); System.out.println(Arrays.asList(strAry_2)); |
3[a, b, c]
3[a, b, c]
1[a,b,c,,]
2[a, b,c,,]
5[a, b, c, , ]
5[a, b, c, , ]
以上基于jdk1.8