Right now I am using
StringUtils.split(String str, char separatorChar)
to split input string with specified separator (,
).
Example input data:
a,f,h
Output
String[] { "a", "f", "h" }
But with following input:
a,,h
It returns just
String[] { "a", "h" }
What I need is just empty string object:
String[] { "a", "", "h" }
How can I achieve this?
If you are going to use StringUtils
then call the splitByWholeSeparatorPreserveAllTokens()
method instead of split()
.
You can just use the String.split(..) method, no need for StringUtils:
"a,,h".split(","); // gives ["a", "", "h"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With