HashMap 的containsKey(Objec…

来源:互联网 发布:知乎豆瓣贴吧猫扑三观 编辑:程序博客网 时间:2024/06/05 09:02
  •  /a**
        * Returns true if this map contains a mapping forthe
        * specified key.
        *
        * @param  key   The key whose presence inthis map is to be tested
        * @return true if this map contains a mapping for thespecified
        * key.
        */


  •     publicboolean containsKey(Object key) {
           Object k = maskNull(key);
           int hash = hash(k.hashCode());
           int i = indexFor(hash, table.length);
           Entry e = table[i];
           while (e != null) {
               if (e.hash == hash && eq(k, e.key))
                   return true;
               e = e.next;
           }
           return false;
        }

0 0
原创粉丝点击