I looked at the documentation on line splitting, but the results are not as expected. When we split a string with a limit argument set to a negative value, it always adds an empty value. Why do this? Consider some cases
String str = "1#2#3#";
System.out.println(str.split("#").length);
System.out.println(str.split("#", -1).length);
What I expect here is like 3 fingerprints.
str = "";
System.out.println(str.split("#").length);
System.out.println(str.split("#", -1).length);
Now, since no match was found, the normal split method without restrictions should print 0, but it creates an array with an empty string.
str = "#";
System.out.println(str.split("#").length);
System.out.println(str.split("#", -1).length);
Now I have a match and the split method works without a limit argument. This is my expected result, but why not create an empty array in this case, as in case 2?
str = "###";
System.out.println(str.split("#").length);
System.out.println(str.split("#", -1).length);
Here the first separation method is as expected, but why does the second give 4 instead of 3?
str = "1#2#3#";
System.out.println(str.split("#", 0).length);
System.out.println(str.split("#", 3).length);
System.out.println(str.split("#", 4).length);
. <= , , . , .