//处理相同的套餐就整合在一起然后把价格加起来
Map<String,OrderItem> hashMap = new HashMap<String, OrderItem>();
for (OrderItem orderItem : orderItemList) {
//如果套餐名为空就不用加进去了
if (orderItem.getpItemName()!=null || !"".equals(orderItem.getpItemName())) {
//map里面相同的套餐名就把里面的价格就相加
if (hashMap.containsKey(orderItem.getpItemName())) {
double price = Double.parseDouble(orderItem.getPrice());
price+= Double.parseDouble(hashMap.get(orderItem.getpItemName()).getPrice());
hashMap.get(orderItem.getpItemName()).setPrice(String.valueOf(price));
} else {
hashMap.put(orderItem.getpItemName(), orderItem);
}<
List相同字段相加的JAVA实现
最新推荐文章于 2024-07-13 02:41:55 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)