String string = "Hello,,l,, World";
String test1[] = string.split(",,");
String test2[] = StringUtils.splitPreserveAllTokens(string , ",,");
test2 has four elements
[Hello, , l, , World]
with two empty elements. Test1 has 3
[Hello, l, World]
which is the expected behavior.
According to the javadoc of splitPreserveAllTokens
following is logical
* StringUtils.splitPreserveAllTokens("::cd:ef", ":") = ["", "", cd", "ef"]
* StringUtils.splitPreserveAllTokens(":cd:ef:", ":") = ["", cd", "ef", ""]
But Still test2 output is not clear to me. Please explain the test2's additional empty elements.