Java代码实现统计每个地区居住的人名
List<String> list = new ArrayList<>();
Map<String, List<String>> map = new HashMap<>();
for (String s : list) {
String[] arr = s.split(',');
String name = arr[0];
String location = arr[1];
if (map.containsKey(location)) {
map.get(location).add(name);
} else {
List<String> nameList = new ArrayList<>();
nameList.add(name);
map.put(location, nameList);
}
}
原文地址: https://www.cveoy.top/t/topic/odea 著作权归作者所有。请勿转载和采集!