String.split()在Java中到底做什么?为什么情况2和情况3的长度不同?
案例1:
String line = "a,b,c,d";
String[] parts = line.split(",");
System.out.println("Length:" + parts.length);
Length: 4
案例2:
String line = "a,,,d";
String[] parts = line.split(",");
System.out.println(parts.length);
Length: 4
案例3:
String line = "a,b,,";
String[] parts = line.split(",");
System.out.println(parts.length);
Length: 2