I have a class
public class Person
{
private int _id;
private String _name;
private int _age;
private List<String> _interests;
public Person()
{
}
public Person(int id, String name, int age, List<String> interests)
{
_id = id;
_name = name;
_age = age;
_interests = interests;
}
public int getId()
{
return _id;
}
public void setId(int id)
{
_id = id;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
}
public int getAge()
{
return _age;
}
public void setAge(int age)
{
_age = age;
}
public List<String> getInterests()
{
return _interests;
}
public void setInterests(List<String> interests)
{
_interests = interests;
}
}
I have main method
public class Main
{
public static void main(String[] args)
{
List<Person> people = Arrays.asList(
new Person(1, "Alex", 23, Arrays.asList("hockey", "football", "google")),
new Person(2, "Brad", 18, Arrays.asList("hockey", "tennis")),
new Person(3, "Felix", 22, Arrays.asList("volleyball", "tennis", "hockey")),
new Person(4, "Brandon", 19, Arrays.asList("hockey", "football", "google"))
);
}
}
The question is, how to print person and their interests without duplicates, that have age more than 21 years using stream and flatMap. So, in general, I should get "Alex" with hockey, football and google and "Felix" with volleyball and tennis (hockey is a duplicate)