TreeMap sort by value

后端 未结 9 846
闹比i
闹比i 2020-11-22 02:44

I want to write a comparator that will let me sort a TreeMap by value instead of the default natural ordering.

I tried something like this, but can\'t find out what

9条回答
  •  隐瞒了意图╮
    2020-11-22 03:33

    This can't be done by using a Comparator, as it will always get the key of the map to compare. TreeMap can only sort by the key.

提交回复
热议问题