java HashMap and HashMultimap 区别

Posted 義丨往昔灬miller

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java HashMap and HashMultimap 区别相关的知识,希望对你有一定的参考价值。

http://stackoverflow.com/questions/19222029/what-is-difference-between-hashmap-and-hashmultimap

 


The difference is that with the second, Core Java implementation,

you need to check whether the Set is there before you insert. Guava‘s Multimap takes care of that for you.

With Core Java:

Set<String> innerSet = opt.get(key);
if (innerSet == null) {
innerSet = new HashSet<String>();
opt.put(key, innerSet);
}
innerSet.add(value);
With Guava:

opt.put(key, value);

以上是关于java HashMap and HashMultimap 区别的主要内容,如果未能解决你的问题,请参考以下文章

Map and HashMap

Java从Hashmap中获取最后一个键

hashmap and hashtable

Read excel and put cell data into HashMap

HashMap And HashSet Complete The Login Function

LinkedHashMap and LinkedHashSet