java8 List 属性分组 属性求和操作

 

1. 分组根据CustomerId

Map> collect = details.stream()
.collect(Collectors.groupingBy(dto::getCustomerId));

2. 单列求和Score

int totalScore = details.stream().mapToInt(dto::getScore).sum();

3. 提取单列数据集合

List ids = details.stream().map(dto::getId).collect(Collectors.toList());

你可能感兴趣的:(java)