gpt4 book ai didi

java - 如何按多个属性 Java8 对 HashMap 条目值进行排序

转载 作者:搜寻专家 更新时间:2023-11-01 01:49:11 24 4
gpt4 key购买 nike

<分区>

如何根据多个属性对 HashMap 条目进行排序。

假设我有一个映射,键为字符串,值为对象。

Map<String, UserMetrics> map = new HashMap<>
map.put("user10",new UserMetrics(1,100,111));
map.put("user3",new UserMetrics(10,330,444));
map.put("user11",new UserMetrics(333,100,555));
map.put("user1",new UserMetrics(1,111,433));

public static class UsageMetrics implements Serializable {
private long param1;
private long param2;
private long param3;....
}

我想先按“param1”对用户进行排序,然后再按“param2”排序

预期结果:<>

user10, UserMetrics(1,100,111)
user1, UserMetrics(1,111,433))
user3, UserMetrics(10,330,444));
user11, UserMetrics(333,100,555))

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com