You could get a set of entries and then sort it however you need.
Here is how you get a set of entries:
Set<Multiset.Entry<Integer>> entries = myIntegerMultiset.entrySet();
And then to sort we can define two comparators:
Comparator<Multiset.Entry<Integer>> byCount = new Comparator<Multiset.Entry<Integer>>() {
int compare(Multiset.Entry<Integer> e1, Multiset.Entry<Integer> e2) {
return e2.getCount() - e1.getCount();
}
}
Comparator<Multiset.Entry<Integer>> byValue = new Comparator<Multiset.Entry<Integer>>() {
int compare(Multiset.Entry<Integer> e1, Multiset.Entry<Integer> e2) {
return e2.getElement() - e1.getElement();
}
}
Then you can provide the comparators to a tree set to get a sorted collection:
Set<Multiset.Entry<Integer>> entries = myIntegerMultiset.entrySet();
Set<Multiset.Entry<Integer>> entriesSortedByCount = Sets.newTreeset(byCount);
entriesSortedByCount.addAll(entries);
Set<Multiset.Entry<Integer>> entriesSortedByValue = Sets.newTreeset(byValue);
entriesSortedByValue.addAll(entries);
Actually, Louis Wasserman's answer is much better, but I will post this one too in case you wanted to customize your sorting.