#247 Filtering People Older Than 18 from Groups
Implement the adultPersons() method:
public class Main {
public static void main(String[] args) {
Group group1 = new Group(Arrays.asList(
new Person("Vova", 16L),
new Person("Nikita", 18L),
new Person("Lesha", 22L)));
Group group2 = new Group(Arrays.asList(
new Person("Sasha", 14L),
new Person("Anya", 20L),
new Person("Dima", 60L)));
throw new UnsupportedOperationException("Implemented it!");
}
/**
* Returns all people older than 18.
*
* @param groups list of groups of people
* @return list of people older than 18
*/
public static List<Person> adultPersons(List<Group> groups) {
throw new UnsupportedOperationException("Implemented it!");
}
}
class Person {
private final String name;
private final Long age;
public Person(String name, Long age) {
this.name = name;
this.age = age;
}
}
class Group {
private final List<Person> people;
public Group(List<Person> people) {
this.people = people;
}
public List<Person> people() {
return people;
}
}
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