1. If the last digit of the string has a value, there is no difference.
2. A number of the last n bits are cut, split ("") will not continue to slice, split ("",-1) will continue to slice
String line = "A b c ";
String [] tmp = Line.split ("");
SYSTEM.OUT.PRINTLN (tmp.length+ "------");
for (int i=0;i<tmp.length;i++) {
System.out.println (i+ "=" +tmp[i]);
}
String [] items = Line.split ("", -1);
System.out.println (items.length+ "========");
for (int i=0;i<items.length;i++) {
System.out.println (i+ "=" +items[i]);
}
Results:
4------
0=a
1=b
2=
3=c
13========
0=a
1=b
2=
3=c
4=
5=
6=
7=
8=
9=
10=
11=
12=
[Java] View plain copy
String = "A b c d";
String [] tmp = Line.split ("");
SYSTEM.OUT.PRINTLN (tmp.length+ "------");
for (int i=0;i<tmp.length;i++) {
System.out.println (i+ "=" +tmp[i]);
}
String [] items = Line.split ("", -1);
System.out.println (items.length+ "========");
for (int i=0;i<items.length;i++) {
System.out.println (i+ "=" +items[i]);
}
Results:
------
0=a
1=b
2=
3=c
4=
5=
6=
7=
8=
9=
10=
11=
12=d
13========
0=a
1=b
2=
3=c
4=
5=
6=
7=
8=
9=
10=
11=
12=d