有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    定义一个类来保存项目

    public record Item {
        String item;
        int count;
    }
    

    使用您最喜欢的json库(我的是Jackson)反序列化到List<Item>

    收集到地图的数据:

    Map<String, Integer> map = list.stream().collect(toMap(Item::getItem, Item::getCount));