HashMap源码解读(二)

本文对HashMap部分源码按照出现顺序进行翻译解读,绿色英文为HashMap源码中的注释,中文为注释对应翻译,代码段中为相应源码  *仅供参考

Hashput中的put方法是一个重要的方法,那么当put方法执行的过程中,HashMap发生了什么改变呢?

put方法:

Associates the specified value with the specified key in this map.If the map previously contained a mapping for the key, the old value is replaced.
@param key key with which the specified value is to be associated
@param value value to be associated with the specified key
@return the previous value associated with <tt>key</tt>, or
<tt>null</tt> if there was no mapping for <tt>key</tt>.
 (A <tt>null</tt> return can also indicate that the map previously associated <tt>null</tt> with <tt>key</tt>.)

将指定的值与此映射中的指定键关联。如果映射之前包含键的映射,则替换旧值。
参数key表示指定值要关联的键,参数value要关联到指定键的值,返回与<tt>键关联的上一个值</tt>,或<tt>null</tt>如果<tt>key</tt>没有映射。
(一个<tt>null</tt>返回值也可以表示先前关联的map <tt>null</tt>与<tt>key</tt>。)

public V put(K key, V value) {
     return putVal(hash(key), key, value, false, true);
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

肆〇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值