I have a collection of Strings, and I would like to convert it to a collection of strings were all empty or null Strings are removed and all others are trimmed.
I can do
In the upcoming latest version(12.0) of Guava, there will be a class named FluentIterable.
This class provides the missing fluent API for this kind of stuff.
Using FluentIterable, you should be able doing something like this:
final Collection filtered = FluentIterable
.from(tokens)
.transform(new Function() {
@Override
public String apply(final String input) {
return input == null ? "" : input.trim();
}
})
.filter(new Predicate() {
@Override
public boolean apply(final String input) {
return !Strings.isNullOrEmpty(input);
}
})
.toImmutableList();