Personally, when I need efficient, mutable ListMultimap with defined iteration order of keys, I use "custom" ListMultimap (created with MultimapBuilder, which is in Guava since v16.0):ListMultimap<String, Integer> treeListMultimap = MultimapBuilder.linkedHashKeys().arrayListValues().build();在v16.0之前,创建自定义Multimap更为冗长(使用 Multimaps.newListMultimap ):Before v16.0 creating custom Multimaps was more verbose (using Multimaps.newListMultimap):/** * Creates {@link ListMultimap} preserving insertion order of keys and values * (it's backed by {@link LinkedHashMap} and {@link ArrayList}). */public static <K, V> ListMultimap<K, V> newLinkedArrayListMultimap() { return Multimaps.newListMultimap( Maps.<K, Collection<V>>newLinkedHashMap(), new Supplier<List<V>>() { @Override public List<V> get() { return Lists.newArrayList(); } });} 这篇关于ArrayListMultimap与LinkedListMultimap有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-29 21:37