mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-01 21:20:54 +07:00
34 lines
682 B
Java
34 lines
682 B
Java
// "Collapse loop with stream 'max()'" "true-preview"
|
|
|
|
import java.util.*;
|
|
|
|
public class Main {
|
|
static class Person {
|
|
String name;
|
|
int age;
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public int getAge() {
|
|
return age;
|
|
}
|
|
|
|
public Person(String name, int age) {
|
|
this.name = name;
|
|
this.age = age;
|
|
}
|
|
}
|
|
|
|
public Person max() {
|
|
List<Person> personList = Arrays.asList(
|
|
new Person("Roman", 21),
|
|
new Person("James", 25),
|
|
new Person("Kelly", 12)
|
|
);
|
|
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(p -> p.age)).orElse(null);
|
|
|
|
return maxPerson;
|
|
}
|
|
} |