Java 代码优化: 使用 Collectors.groupingBy 简化数据分组操作
<p>private Collection<List<List<Object>>> getSheetDatas(final String activityId) {\n final List<MidLevelDemocracyEvaluationVO> midLevelDemocracyEvaluations = getMidLevelDemocracyEvaluations(activityId);\n final Map<Integer, List<List<Object>>> collect = CollectionUtils.emptyIfNull(midLevelDemocracyEvaluations)\n .stream()\n .collect(Collectors.groupingBy(\n MidLevelDemocracyEvaluationVO::getOrgSort,\n Collectors.mapping(this::createDataObjects, Collectors.toList())));\n return collect.entrySet().stream()\n .sorted(Map.Entry.comparingByKey())\n .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,\n (oldValue, newValue) -> oldValue, LinkedHashMap::new)).values();\n}</p>
原文地址: https://www.cveoy.top/t/topic/p9Se 著作权归作者所有。请勿转载和采集!