1.過濾出想要的結果 取第一個
Optional stock = vo.stream().filter(v->“100”.equals(page.getProductCode())).findFirst();
if (stock.isPresent()) {
StockWarQueryVo stock4 = stock.get();
stockVo.setProductName(stock4.getProductName());
}
2.過濾出想要的結果集
List vehicleInfos = list.stream().filter(a ->100==a.getSysOrgId()).collect(Collectors.toList());
3.取出ids
List productCodes = vo.stream().map(StockWarQueryVo::getProductCode).collect(Collectors.toList());
4.list轉爲id爲key的map
Map<Long, User> maps = userList.stream().collect(Collectors.toMap(User::getId,Function.identity()));
5.根據屬性分組
Map<String, List> detailsMap01 = list.stream()
.collect(Collectors.groupingBy(User::getId));
6.排序
(1)升序
Collections.sort(result, Comparator.comparing(ProVendorCategoryTreeVo::getClassifySort));
(2)降序
Collections.sort(result, Comparator.comparing(ProVendorCategoryTreeVo::getClassifySort).reversed());
(3)先升序再降序
Collections.sort(result, Comparator.comparing(ProVendorCategoryTreeVo::getClassifySort)).thenComparing(ProVendorCategoryTreeVo::getId).reversed();