Reputation: 65
What is the equivalent for this C# code in Java?
string receivedData = …;
string splittedValues = receivedData.Split("&", StringSplitOptions.RemoveEmptyEntries);
Upvotes: 1
Views: 295
Reputation: 200216
final String[] splittedValues = receivedData.replaceFirst("^&+","").split("&+");
Upvotes: 6
Reputation: 198321
With Guava:
Iterable<String> splitStrings =
Splitter.on('&').omitEmptyStrings().split(string);
(Disclosure: I contribute to Guava.)
Upvotes: 0
Reputation: 56819
For the particular code above, you can first:
.replaceAll("(^&+|&+$)", "")
.split("&+")
Without the first step clean up, empty string will be in the result of splitting the string "&&sdfds"
(leading delimiter).
Upvotes: 0