码迷,mamicode.com
首页 > 编程语言 > 详细

java HashMap and HashMultimap 区别

时间:2017-04-30 17:20:56      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:href   guava   diff   hash   put   flow   add   and   check   

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

标签:href   guava   diff   hash   put   flow   add   and   check   

原文地址:http://www.cnblogs.com/qbmiller/p/6789659.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!