Skip to content

Instantly share code, notes, and snippets.

@defndaines
Created June 4, 2016 01:40
Show Gist options
  • Select an option

  • Save defndaines/3394f52f5cd3d5469d185d6f342d81dc to your computer and use it in GitHub Desktop.

Select an option

Save defndaines/3394f52f5cd3d5469d185d6f342d81dc to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
List<Long> numbers = Collections.emptyList();
Optional<Long> result = numbers.stream().reduce(Math::max);
// result.orElse(-1L) == -1L;
numbers = Arrays.asList(52L, 127L, 1337L);
result = numbers.stream().reduce(Math::max);
// result.get() == 1337L;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment