利用map 对list进行对某一字段分组

Map> proMap = new HashMap<>();
        for (NumberAssignVo numberAssignVo : numberAssignVos) {
            List tempList = proMap.get(numberAssignVo.getProviderName());
            if (tempList == null) {
                tempList = new ArrayList<>();
                tempList.add(numberAssignVo);
                proMap.put(numberAssignVo.getProviderName(), tempList);
            } else {
                tempList.add(numberAssignVo);
            }
        }

        Map>> resultMap = new HashMap<>();
        for(String providerName : proMap.keySet()){
            List tempList1 = proMap.get(providerName);
            Map> countryMap = new HashMap<>();
            for (NumberAssignVo numberAssignVo1 : tempList1) {
                List tempList2 = countryMap.get(numberAssignVo1.getCountryEnName());
                if (tempList2 == null) {
                    tempList2 = new ArrayList<>();
                    tempList2.add(numberAssignVo1);
                    countryMap.put(numberAssignVo1.getCountryEnName(), tempList2);
                } else {
                    tempList2.add(numberAssignVo1);
                }
            }
            resultMap.put(providerName,countryMap);
        }

你可能感兴趣的:(数据库相关)