I want to split ",,," to a array of 4 "" using the String.split()
Here is my code:
String str = ",,,";
String[] tokens = str.split(",");
However, the result tokens were an an empty array: [], rather than an array of 4 "" (["","","",""]) as I wanted.
I have tested to change the str a little bit:
String str = ",,,1";
String[] tokens = str.split(",");
This time the result tokens were ["","","","1"]. This is close to what I want, but I really do not want to add this "1" before doing the split.
The problem is basically, the String.split() will return an empty array if it contains only empty elements "".
Can you help solve the problem?