How to sort guava multimap? (KEY=DATE)

こ雲淡風輕ζ 提交于 2019-11-30 03:44:07

问题


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?


回答1:


Guava team member here.

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

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


来源:https://stackoverflow.com/questions/10589716/how-to-sort-guava-multimap-key-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!