Find elements, map and extract in java using streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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