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);
    }
}
已知 list中存储了每个人的籍贯信息姓名和籍贯之间用逗号隔开了例如张三丰北京如下代码的作用是统计出每个地区居住的人名存放在map中请补全代码。

原文地址: https://www.cveoy.top/t/topic/fm9z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录