Guava:Multimap 一个key映射多个值
java guava    2018-08-31 23:56:51    4    0    0
cqc   java guava
Multimap
允许一个key映射多个值
通常比较少直接使用Multimap,而是使用ListMultimap或SetMultimap

常用API
SignatureDescriptionEquivalent
put(K, V)Adds an association from the key to the valuemultimap.get(key).add(value)
putAll(K, Iterable<V>)Adds associations from the key to each of the values in turnIterables.addAll(multimap.get(key), values)
remove(K, V)Removes one association from key to value and returns true if the multimap changed.multimap.get(key).remove(value)
removeAll(K)Removes and returns all the values associated with the specified key. The returned collection may or may not be modifiable, but modifying it will not affect the multimap. (Returns the appropriate collection type.)multimap.get(key).clear()
replaceValues(K, Iterable<V>)Clears all the values associated with key and sets key to be associated with each of values. Returns the values that were previously associated with the key.multimap.get(key).clear(); Iterables.addAll(multimap.get(key), values)

实现类
ImplementationKeys behave like...Values behave like..
ArrayListMultimapHashMapArrayList
HashMultimapHashMapHashSet
LinkedListMultimap *LinkedHashMap``*LinkedList``*
LinkedHashMultimap**LinkedHashMapLinkedHashSet
TreeMultimapTreeMapTreeSet
ImmutableListMultimapImmutableMapImmutableList
ImmutableSetMultimapImmutableMapImmutableSet



上一篇: Guava: I/O utilities

下一篇: Guava:Table 三维数据结构

文档导航