Skip to content

Instantly share code, notes, and snippets.

@liviutudor
Last active April 1, 2017 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liviutudor/cc9cb7bd450688461515b2cfa0248368 to your computer and use it in GitHub Desktop.
Save liviutudor/cc9cb7bd450688461515b2cfa0248368 to your computer and use it in GitHub Desktop.
Find elements, map and extract in java using streams
public Optional<Double> findExtractAndMax(Collection<Employee> collection, String name) {
return collection.stream().filter(e -> e.firstName.equals(name)).map(e -> e.salary).max((a, b) -> (int) Math.signum(a - b));
}
//usage
double sal = findExtractAndMax(collection, "Bob");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment