For some special cases, split does not retain the entire element after splitting
Here's an example:
String x = "a,,,,,,"x.split(","); for (int i=0;i<y.length;i++) { System.out.println (y[i]);}
Output Result:
The first letter is only split, and the empty string after the default is not preserved.
Later thought of using the StringUtils function, looked up, modified as follows:
String x = "a,,,,,,"stringutils.splitpreservealltokens(x, ","); for (int i=0;i<y.length;i++) { System.out.println (y[i]);}
Output Result:
public static string[] Splitpreservealltokens (String str, char Separatorchar)
Splits the string str into an array, with the character (Separatorchar) as the delimiter, and retains all the identities.
The StringUtils function is still very powerful, and the problem with strings is not going to look good here.
If I was in ACM, I knew this stuff, and a lot of problems were solved t_t
Problem where split function in Java becomes null after splitting