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 List
s, use MultimapBuilder
:
使用TreeMultimap,或者如果需要映射到列表,请使用MultimapBuilder:
return MultimapBuilder.treeKeys().arrayListValues().build()
#1
16
Guava team member here.
番石榴队成员在这里。
Use TreeMultimap
, or if you need to map into List
s, use MultimapBuilder
:
使用TreeMultimap,或者如果需要映射到列表,请使用MultimapBuilder:
return MultimapBuilder.treeKeys().arrayListValues().build()