How to split a line without spaces of continuous delimiter

how to split a line as "x~y~z~~~~~"with a separator ~, we must split it as 7 elements. but when processing using the method string.split("~")it gives only 3 lines

+5
source share
1 answer

Try the following:

String [] = data.split ("~", -1);

refer to Javadoc for the split method using two arguments for details.

When calling String.split (String), it calls String.split (String, 0) and discards the final empty lines (as the docs say) when calling String.split (String, n) with n <0, it will not throw anything.

+9
source

All Articles