如何对番石榴复合图进行排序? (KEY = DATE) [英] How to sort guava multimap? (KEY=DATE)

查看:92
本文介绍了如何对番石榴复合图进行排序? (KEY = DATE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个

Multimap<Date,Invoice> multimap = ArrayListMultimap.create();

。我想知道如何在多图中排序日期键。

from guava. I was wondering how to SORT the the Date key in the multimap.

目前,我这样做:

        Iterator<Date> dateItr = multimap.keySet().iterator();
        Set<Date> treeSet = new TreeSet<Date>(Collections.reverseOrder());

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

and later I loop through the treeSet iterator. Any idea how to avoid this circumvention?

推荐答案

番石榴团队成员在这里。

Guava team member here.

使用 TreeMultimap ,或者如果您需要映射到 List ,请使用 MultimapBuilder

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

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

这篇关于如何对番石榴复合图进行排序? (KEY = DATE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆