如何对番石榴复合图进行排序? (KEY = DATE)

时间:2022-09-24 19:13:36

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?

然后我循环遍历treeSet迭代器。知道如何避免这种规避吗?

1 个解决方案

#1


16  

Guava team member here.

番石榴队成员在这里。

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

使用TreeMultimap,或者如果需要映射到列表,请使用MultimapBuilder:

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

#1


16  

Guava team member here.

番石榴队成员在这里。

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

使用TreeMultimap,或者如果需要映射到列表,请使用MultimapBuilder:

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