java8 从对象集合中取出某个字段的集合

 List list = Arrays.asList(new Student(1l, "one"), new Student(2l, "two"), new Student(3l, "tree"));
    //从list集合中,取出字段name的列表
    List names = list.stream().map(p -> p.getHome()).collect(Collectors.toList());
    System.out.println(names);

你可能感兴趣的:(java)