java - 按值 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;
}
解决方案
推荐阅读
- python-3.x - 基于 if 语句写入或读取文件
- indexeddb - How to define and use database relationships in dexie js?
- html - 调整窗口大小时如何阻止导航栏中的文本上下移动
- javascript - 同步两个 HTTP 请求
- python - 如何使用 Pyspark 对列表列表中的元素进行平方?
- angular - 使用 mat-select 和 formControl 设置默认值
- java - 在学习编程的同时学习代码约定
- java - 如何按 id 对 ArrayList 进行排序并添加到 ArrayList
> - java - 为什么 JSONproblem 让我着迷:JSONObject 文本必须在字符 1 处以 '{' 开头
- javascript - 节点模块读取所有文件类型的内容