从List集合中取出某一属性的值的集合
作者:互联网
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class test {
public static void main(String[] args) {
List<Student> students=new ArrayList<Student>();
Student student=new Student("小王",18);
Student student1=new Student("小张",19);
students.add(student);
students.add(student1);
List<Integer> productId=students.stream().map(Student::getAge).collect(Collectors.toList());
System.out.printf(productId.toString());
}
}
标签:java,students,List,util,某一,Student,集合,new 来源: https://blog.csdn.net/lihua5419/article/details/95474852