首页 > 解决方案 > 按值 HashMap 排序

问题描述

我有一个 HashMap HashMap<String, List<OtherModel>>- 我需要按第一个List<OtherModel>元素的字段排序,有什么想法吗?)

我的代码不正确,例如:

 public static HashMap<String, List<AsoInfoModel>> sortAsoByValue(HashMap<String, List<AsoInfoModel>> items) {
        List<Map.Entry<String, List<AsoInfoModel>>> list = new LinkedList<>(items.entrySet());
        list.stream().sorted(Comparator.comparing(Map.Entry::getValue::AsoInfoModel::position, Comparator.naturalOrder());

        HashMap<String, List<AsoInfoModel>> temp = new LinkedHashMap<>();
        for (Map.Entry<String, List<AsoInfoModel>> aa : list) {
            temp.put(aa.getKey(), aa.getValue());
        }
        return temp;
    }

标签: javahashmap

解决方案


推荐阅读