How to sort a map(?,B) on the values in Java with google collections ordering function, if B is a class, which has a field of type double, which should be used for ordering.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here's a snippet that uses a generic method that takes a
Map<K,V>
and aComparator<? super V>
, and returns aSortedSet
of itsentrySet()
sorted on the values using the comparator.On Google Ordering
The above solution uses a
Comparator
, so you can easily use the above method to useOrdering
instead.Collections.sort(map.values(), myComparator); Create myComparator as Comparator to compare the B objects by the double field.