从List集合中取出某一属性的值的集合

 

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class test {

    public static void main(String[] args) {

        List students=new ArrayList();
        Student student=new Student("小王",18);
        Student student1=new Student("小张",19);
        students.add(student);
        students.add(student1);
        List productId=students.stream().map(Student::getAge).collect(Collectors.toList());
        System.out.printf(productId.toString());
    }
}

 

你可能感兴趣的:(java,java8)