How to sort a treemap based on its values?

前端 未结 9 1024
萌比男神i
萌比男神i 2020-12-01 04:53

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

9条回答
  •  长情又很酷
    2020-12-01 05:18

    Apache Commons Collections has a TreeBidiMap:

    This class guarantees that the map will be in both ascending key order and ascending value order, sorted according to the natural order for the key's and value's classes.

    There's a Java5-generics port of it here.

提交回复
热议问题