首页 > 代码库 > java HashMap and HashMultimap 区别

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 区别