8

I have a

Multimap<Date,Invoice> multimap = ArrayListMultimap.create();

from guava. I was wondering how to SORT the the Date key in the multimap.

Currently, I'm doing this:

        Iterator<Date> dateItr = multimap.keySet().iterator();
        Set<Date> treeSet = new TreeSet<Date>(Collections.reverseOrder());

and later I loop through the treeSet iterator. Any idea how to avoid this circumvention?

adhg
  • 10,437
  • 12
  • 58
  • 94
  • 2
    [TreeMultimap](http://guava-libraries.googlecode.com/svn/tags/release03/javadoc/com/google/common/collect/TreeMultimap.html) – Beau Grantham May 14 '12 at 19:21

1 Answers1

16

Guava team member here.

Use TreeMultimap, or if you need to map into Lists, use MultimapBuilder:

return MultimapBuilder.treeKeys().arrayListValues().build()
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413