Код: Выделить всё
public class Student {
String name;
int age;
public Student(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
Код: Выделить всё
public static List createListOfStudents() {
List listOfStudents = new ArrayList < > ();
Student s1 = new Student("Anchit", 20);
Student s2 = new Student("Peter", 19);
Student s3 = new Student("Martin", 22);
Student s4 = new Student("Sam", 21);
listOfStudents.add(s1);
listOfStudents.add(s2);
listOfStudents.add(s3);
listOfStudents.add(s4);
return listOfStudents;
}
List listOfStudents = createListOfStudents();
listOfStudents.stream().map(x -> x.getName()).map(x -> x.getAge());
Подробнее здесь: https://stackoverflow.com/questions/784 ... iple-times