HashMap是否允许重复? [英] HashMap allows duplicates?

查看:589
本文介绍了HashMap是否允许重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对HashMap有怀疑,因为我们都知道HashMap允许有一个空的键和值对,我的问题在这里是

如果我这样写, p>

  m.put(null,null); 
m.put(null,a);

它会抛出一个(错误或异常),还是会覆盖该值或者值是什么

解决方案

Hashmap类型如果hashmap键是相同的键,则覆盖该键

  map.put(1,1111); 
map.put(1,2222);

输出

  key:value 
1:2222


I have a doubt regarding HashMap, as we all know HashMap allows one null key and value pair, My question here is

If I wrote like this,

m.put(null,null);
m.put(null,a);

Will it throw a (error or exception) or will it override the value or what will be the value of returing??

解决方案

Hashmap type Overwrite that key if hashmap key is same key

map.put("1","1111");
map.put("1","2222");

output

key:value
1:2222

这篇关于HashMap是否允许重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆