limit是正整數時表示分割成幾個字串,先分割前面的
limit是負整數時表示完全分割,子串可能會是""
limit是0時,與split("分割符")同義,子串不會是""
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