An empty string called split method to return a string array whose length equals 1.

I recently found a weird issue: an empty string called split method to return a string array, the length of which equals 1, instead of zero.

String str = "";
String[] splits = str.split(",");
System.Out.println(splits.length);

Console output : 1.


However, a string contained a comma split by the same comma into a string array object, the length of which equals zero.

String str = ",";
String[] splits = str.split(",");
System.Out.println(splits.length);

Console output : 0.


你可能感兴趣的:(An empty string called split method to return a string array whose length equals 1.)