将一个对象集合中的某一个字段取出来生成一个新的集合

List<Store> storeList = storeService.listStore(page, size);
List<Integer> collect = storeList.stream().map(s -> s.getStoreId()).collect(Collectors.toList());
//OR 
List<Integer> collect = storeList.stream().map(Store::getStoreId).collect(Collectors.toList());

将List对象集合转化为key为对象ID的Map

List<Specification> specifications = specificationService.listSpecification();
Map<Integer, Specification> collect = specifications.stream().collect(Collectors.toMap(Specification::getSpecificationId, Function.identity()));

跟据某个属性分组

Map<String, List<PersonData>> collect = list.stream().collect(Collectors.groupingBy(PersonData::getType));

根据某个属性分组,汇总某个属性

Map<String, Integer> collect2 = list.stream().collect(Collectors.groupingBy(PersonData::getType,Collectors.summingInt(PersonData::getAge)));

根据某个属性添加条件过滤数据

list = list.stream().filter(u -> !u.getType().equals("访客")).collect(Collectors.toList());

判断一组对象里面有没有属性值是某个值

boolean add = list.stream().anyMatch(m -> "王五".equals(m.getName()));