1,找出list重複的數據
List<String> list = Arrays.asList("112", "113");
Map<String, Long> collect = list.stream().collect(Collectors.groupingBy(User::getName, Collectors.counting()));
System.out.println(collect);
public static List<String> getKeyByValue(Map<String, Long> collect){
List list = new ArrayList();
for(Map.Entry entry: collect.entrySet()){
if(entry.getValue() > 1){
list.add(entry.getKey().toString())
}
}
return list;
}
2,對list中某元素求和
list.stream().collect(Collectors.summingInt(xxxPo.getCounts));
list.stream().mapToInt().sum(xxxPo::getCounts)
list.stream().map(xxxPo::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);