Created
April 13, 2017 07:14
-
-
Save zhugw/1d228a91bed1ab2cfe5a9a7f15c03014 to your computer and use it in GitHub Desktop.
Java8_grouping_by_mapping_and_join
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String,String> areaCode2AddrMap = new HashMap<>(); | |
for(AreaCode areaCode:areaCodeList){ | |
if(areaCode2AddrMap.get(areaCode.getCode())!=null){ | |
String value = areaCode2AddrMap.get(areaCode.getCode())+","+areaCode.getAddr(); | |
areaCode2AddrMap.put(areaCode.getCode(),value); | |
}else{ | |
areaCode2AddrMap.put(areaCode.getCode(),areaCode.getAddr()); | |
} | |
} | |
Map<String, String> areaCode2AddrMap = areaCodeList.stream().collect(groupingBy(AreaCode::getCode, mapping(AreaCode::getAddr, joining(",")))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment