import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
class Student {
private String name;
private int age;
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
public class Main {
public static void main(String[] args) {
List<Student> studentList = new ArrayList<>();
studentList.add(new Student("Alice", 20));
studentList.add(new Student("Bob", 16));
studentList.add(new Student("Charlie", 22));
List<String> filteredNames = studentList.stream()
.filter(student -> student.getAge() > 18)
.map(Student::getName)
.collect(Collectors.toList());
System.out.println(filteredNames);
}
}