简体   繁体   中英

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?

Guava team member here.

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

return MultimapBuilder.treeKeys().arrayListValues().build()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM