list对象中根据某个字段排序 汇总某个数据

碰到一个需求 需要根据list集合中的对象ID进行分组然后再对一个数据汇总,但是那个数据是string类型的

 List<LoopLineDataVO> loopLineDataVOS = loopLineDataMapper.selectByMap(map);
Map<Integer, Double> collect2 = loopLineDataVOS.stream().collect(Collectors.groupingBy(LoopLineDataVO::getLoopDataId,Collectors.summingDouble(LoopLineDataVO::getElectricityA)));

Collectors.summingDouble() 这里string怎么转化为double类型啊


Map<Integer, Double> collect2 = loopLineDataVOS.stream().collect(Collectors.groupingBy(LoopLineDataVO::getLoopDataId,
                Collectors.summingDouble(
                        dataVO->{
                            return Double.parseDouble(dataVO.getElectricityA());
                        }
                )));

如果是getElectricityA这个数据是String类型,可以在LoopLineDataVO里面再写一个get方法

public double getDoubleElectricityA(){
return Double.valueOf(getElectricityA());
}