#46 Filtering a List of People by Age
Select people older than 40 and print them:
import java.util.Arrays;
import java.util.List;
public class TestSteam {
public static void main(String[] args) {
List<Person> persons = Arrays.asList(
new Person("a", 23),
new Person("b", 25),
new Person("c", 45),
new Person("d", 63),
new Person("e", 65),
new Person("f", 33)
);
List<String> names ; //your code
System.out.println(names);
}
static class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor