What is the equivalent for this C# code in Java?
string receivedData = …;
string splittedValues = receivedData.Split("&", StringSplitOptions.RemoveEmptyEntries);
final String[] splittedValues = receivedData.replaceFirst("^&+","").split("&+");
With Guava:
Iterable<String> splitStrings =
Splitter.on('&').omitEmptyStrings().split(string);
(Disclosure: I contribute to Guava.)
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).