StreamToLoop: support Optional unwrap if possible

This commit is contained in:
Tagir Valeev
2016-12-09 15:17:26 +07:00
parent ae273b6c24
commit 8e128b7f32
27 changed files with 425 additions and 90 deletions
@@ -2,20 +2,17 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class Main {
private static String test(List<String> list) {
if (list == null) return null;
else {
Optional<String> found = Optional.empty();
for (String str : list) {
if (str.contains("x")) {
found = Optional.of(str);
break;
return str;
}
}
return found.orElse(null);
return null;
}
}