如何组做网站,提升网站安全,dashicon wordpress,钢材料 网站建设 中企动力stream真的没有什么好说的#xff0c;filter、map这俩常用的程序可以说每天都要写好几遍#xff0c;那么问题来了#xff0c;为什么还要拿出来讲讲呢#xff1f;当然不可能是因为想要划水#xff0c;主要是工作中它的其他相关方法也有不少涉及。以下是按照不同需求涉及到的… stream真的没有什么好说的filter、map这俩常用的程序可以说每天都要写好几遍那么问题来了为什么还要拿出来讲讲呢当然不可能是因为想要划水主要是工作中它的其他相关方法也有不少涉及。以下是按照不同需求涉及到的方法。 统计list中某个字段的总和
方法一
BigDecimal sumjsonObjects.stream()
.filter(d- childIds1.indexOf(d.getLong(subarea_id))!-1).map(d-d.getBigDecimal(result)).reduce(BigDecimal.ZERO, BigDecimal::add);方法二
double planValue maps.stream()
.mapToDouble(d -Double.valueOf(d.get(plan_value).toString())).sum();
Integer chargeTotalLevel chargingPileList.stream().mapToInt(LowVoltageChargePile::getLevel).sum();按照某个字段进行排序 ListPerson sortedPeople people.stream().sorted(Comparator.comparing(Person::getAge)).sorted(Comparator.reverseOrder()).collect(Collectors.toList());统计满足某个条件的集合子元素数目
long count jsonObjects.stream()
.map(jsonObj - jsonObj.getLong(father_id))
.filter(id - childIds1.contains(id))
.count();统计当年12个月中的value但是hcPowerStatistics未必有12个
//原本是有数据的这里随便搞一下
ListMapString, Object hcPowerStatisticsnew ArrayList();
MapString, MapString, Object hcPowerMap hcPowerStatistics.stream().collect(Collectors.toMap(d - d.get(month).toString(), Function.identity()));for (int month 1; month 12; month) {String monthString String.format(%02d, month);String yearMonth year - monthString;MapString, Object filterList hcPowerMap.get(yearMonth);double power (filterList ! null) ? (double) filterList.get(total_value) : 0;powerList.add(power);
}list根据筛选条件确定只有一条数据的情况下
Integer result numbers.stream().filter(number - number 5) // 筛选条件.findFirst() // 获取第一个满足条件的对象.orElse(0); // 如果不存在满足条件的对象则返回默认值0我不清楚现在为什么要戒烟戒烟能带给我什么好处呢让我有套上枷锁、给人当牛做马的资格多活10年又能改变什么在我看来一直在走正确的路人是会出毛病的。