Reputation: 1677
how to split the string like "x~y~z~~~~~"
with delimiter ~
,we have to split this as 7 elements. but while processing with string.split("~")
method it gives 3 strings only
Upvotes: 5
Views: 1903
Reputation:
Try below :
String[] = data.split("~", -1);
refer Javadoc for the split method taking two arguments for details.
When calling String.split(String), it calls String.split(String, 0) and that discards trailing empty strings (as the docs say it), when calling String.split(String, n) with n < 0 it won't discard anything.
Upvotes: 9