#46 Filtering a List of People by Age

Companies:
Unknown company
Themes:
JavaStreams & LambdasPractice

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

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