I would like to have a c.g.c.c.Multimap that is sorted based on keys only. The values shouldn\'t be sorted. I\'ve tried to build something with guava\'s T
Best solution which always works for me is to use Multimap & TreeMultiMap. this will order results in ascending order on keys even if you have multiple duplicate keys. Solution below:
Multimap map= TreeMultimap.create(Ordering.natural().reverse(), Ordering.natural());
if (!map.isEmpty()) {
printMap(map);
}
public static void printMap(Multimap map) throws Exception {
for (Map.Entry entry : map.entries()) {
System.out.println("Key : " + entry.getKey()
+ " Value : " + entry.getValue());
}
}