Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. Optional<Integer> a = Optional.of(1);
  2. Optional<Integer> b = Optional.of(1);
  3. Optional<Integer> c = Optional.of(1);
  4.  
  5. ...
  6. if (a.isPresent() && b.isPresent() && c.isPresent()) {
  7. return a.get() + b.get() + c.get();
  8. }
  9. ...
  10.  
  11. Stream.of(a, b, c)
  12. .filter(Optional::isPresent)
  13. .map(Optional::get)
  14. .mapToInt(Integer::intValue)
  15. .sum();
  16.  
  17. Optional<Integer> a = Optional.of(1);
  18. Optional<Integer> b = Optional.of(1);
  19. Optional<Integer> c = Optional.of(1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement