public static void main(String[] args) {
List<Student> list = Lists.newArrayList();
list.add(new Student("id1", "张三", "男", 18));
list.add(new Student("id2", "李四", "男", 20));
list.add(new Student("id3", "王五", "女", 19));
list.add(new Student("id4", "赵六", "女", 22));
//获取id的集合
List<String> idList = list.stream().map(Student::getId()).collect(Collectors.toList());
//过滤
List<Student> l1 = list.stream().filter(student -> student.getSex().equals("男")).collect(toList());
//获取map
Map<String, String> map = list.stream().collect(Collectors.toMap(Student::getId(), Student::getName()));
//是否存在
boolean isExist = list.stream().anyMatch(item -> item.getId().equals("id1"));
}
注:
.collect(toList()) 可以写成 .collect(Collectors.toList());