- 抽取集合对象属性
- List转set
Set<String> kSet = keys.stream().map(k -> k).collect(Collectors.toSet());
- List转map
Map<String,InventoryAdjustment> adjustments = list.stream()
.map(InventoryChange::getAdjustment).collect(Collectors.toList())
.stream().collect(Collectors.toMap(InventoryAdjustment::getCreatedAt, adjustment->adjustment,(key1, key2)->key1));
- List去重(distinct())
List<Integer> goodsIds = list.stream().map(OrderDetail::getGoodsId).distinct().collect(Collectors.toList());
-
内部操作数据
List<MiddleRedisSkuStock> skuStockList = values.stream().filter(StringUtils::isNotBlank).map(
value -> JSON.parseObject(value, MiddleRedisSkuStock.class)
).collect(Collectors.toList());
- 数值计算
- BigDecimal求和
BigDecimal amount = list.stream().map(OrderDetail::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
- Integert求和
list.stream().mapToInt(SalesOrderDetail::getGoodsSum).sum();
- 获取集合属性最小值
BigDecimal minUnitPrice = list.stream().map(GoodsSku::getUnitPrice).min((u1, u2)->u1.compareTo(u2)).get();
一只渣渣
发布了16 篇原创文章 · 获赞 0 · 访问量 2490
私信
关注