I would like to move some method into java8 functional style.
public static String foo(List<String> arguments, List<String> conditions) {
for (String s : conditions) {
for (String argument : arguments) {
if (argument.contains(s)) {
return argument;
}
}
}
return "";
}
My current idea is:
public static String fooFunctional(List<String> arguments, List<String> conditions) {
return conditions.stream()
.flatMap(condition -> arguments.stream()
.filter(argument -> argument.contains(condition))
.findFirst()
.map(Stream::of)
.orElseGet(Stream::empty))
.findFirst()
.orElse("");
}
Is there any shorter version then proposed above?