如何根据树的值对树图进行排序? [英] How to sort a treemap based on its values?

查看:98
本文介绍了如何根据树的值对树图进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用其值而不是键对树图进行排序?

How can I sort a treemap using its values rather than the key?

推荐答案

您无法运行TreeMap的比较器仅对着钥匙,例如看到这个构造函数

You cannot as the TreeMap's comparator is run against the keys only, e.g. see this constructor.

无论如何,您可以使用多个集合,使用TreeMap(或更确切地说是HashMap)按键查找元素,并使用SortedSet迭代值。

Anyway, you can use multiple Collections, use the TreeMap (or rather HashMap) for looking up elements by keys, and have a SortedSet to iterate on the values.

这篇关于如何根据树的值对树图进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆