java jdk8 grammar record
1. The desired result was filtered off to take a first
Optional stock = vo.stream().filter(v->“100”.equals(page.getProductCode())).findFirst();
if (stock.isPresent()) {
StockWarQueryVo stock4 = stock.get();
stockVo.setProductName(stock4.getProductName());
}
2. Filter out the desired result set
List vehicleInfos = list.stream().filter(a ->100==a.getSysOrgId()).collect(Collectors.toList());
3. Remove ids
List productCodes = vo.stream().map(StockWarQueryVo::getProductCode).collect(Collectors.toList());
4.list id to key into the map
Map<Long, User> maps = userList.stream().collect(Collectors.toMap(User::getId,Function.identity()));
The attribute grouping
Map<String, List> detailsMap01 = list.stream()
.collect(Collectors.groupingBy(User::getId));
6. Sort
(1) ascending
Collections.sort(result, Comparator.comparing(ProVendorCategoryTreeVo::getClassifySort));
(2) Descending
Collections.sort(result, Comparator.comparing(ProVendorCategoryTreeVo::getClassifySort).reversed());
(3) first descending and then ascending
Collections.sort(result, Comparator.comparing(ProVendorCategoryTreeVo::getClassifySort)).thenComparing(ProVendorCategoryTreeVo::getId).reversed();