#247 Filtering People Older Than 18 from Groups

Companies:
Digitalleague Dcloud
Themes:
JavaStreams & LambdasPractice

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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in