stream find max

Solutions on MaxInterview for stream find max by the best coders in the world

showing results for - "stream find max"
Luis
08 Sep 2016
1employees.stream().max(comparator).get();
Isabell
09 Apr 2018
1class Person {
2    String name;
3    Integer age;
4      
5    // standard constructors, getters and setters
6}
7We want to find the Person object with the minimum age:
8
9Person alex = new Person("Alex", 23);
10Person john = new Person("John", 40);
11Person peter = new Person("Peter", 32);
12List<Person> people = Arrays.asList(alex, john, peter);
13
14// then
15Person minByAge = people
16.stream()
17.min(Comparator.comparing(Person::getAge));
18