Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort guava multimap? (KEY=DATE)

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?

like image 698
adhg Avatar asked May 14 '12 19:05

adhg


1 Answers

Guava team member here.

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

return MultimapBuilder.treeKeys().arrayListValues().build()
like image 102
Louis Wasserman Avatar answered Oct 17 '22 06:10

Louis Wasserman