[英]How to sort Java Map by value and if value is the then by key
I need to sort this TreeMap by values and if value is the same like 1 or 2 in this case then I need to sort these elements by their keys. 我需要按值对TreeMap进行排序,并且在这种情况下,如果value像1或2一样,则需要按其键对这些元素进行排序。 How can I do it? 我该怎么做?
{65=2, 67=1, 69=4, 72=2, 73=5, 77=1, 78=2, 79=3, 81=1, 83=7, 84=6, 85=2, 87=2, 89=1}
So the result would looks like this 所以结果看起来像这样
{83=7, 84=6, 73=5, 69=4, 79=3, 65=2, 72=2, 78=2, 85=2, 87=2, 67=1, 77=1, 81=1, 89=1}
Thank you for help. 谢谢你的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.