pmad
pmad

Reputation: 1677

How to split a string without spaces of continuous delimiter

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

Answers (1)

user319198
user319198

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

Related Questions