1. 程式人生 > >Java 8流式操作

Java 8流式操作

  1. 集合根據id分組
Map<String, List<AreaBO>> areaGroupByLevel = areaList.stream()
				.collect(Collectors.groupingBy(AreaBO::getParent));

2.過濾

List<SkuSupermarketBO> priceList = value.stream().filter(item -> item != null && item.getPrice() != null)
					.collect
(Collectors.toList());

3.提取id重組集合

List<Long> skuIdList = SkuCommunityList.stream()
.collect(Collectors.mapping(SkuCommunityBO::getGoodsSkuId, Collectors.toList()));