package com.example; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class CompetitionMain { private static List competList = new ArrayList<>(); public static void main(String[] args) { competList.add(new CompetitionFoot(18, "footA")); competList.add(new CompetitionFoot(30, "footA")); competList.add(new CompetitionFoot(40, "footA")); competList.add(new CompetitionHand(18, "handA")); competList.add(new CompetitionHand(30, "handA")); competList.add(new CompetitionHand(40, "handA")); List ageList = findByAge(competList, 18); List nameList = findByName(ageList, "footA"); for (Competition competition : nameList) { System.out.println(competition.name); } } public static List findByAge(List competitions, int age) { return competitions.stream().filter(competition -> competition.age == age).collect(Collectors.toList()); } public static List findByName(List competitions, String name) { return competitions.stream().filter(competition -> competition.name.equals(name)).collect(Collectors.toList()); } } abstract class Competition { public int age; public String name; public Competition(int age, String name) { this.age = age; this.name = name; } } class CompetitionFoot extends Competition { public CompetitionFoot(int age, String name) { super(age, name); } // additional fields } class CompetitionHand extends Competition { public CompetitionHand(int age, String name) { super(age, name); } // additional fields }