问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

hashMap怎么实现

发布网友 发布时间:2022-04-24 02:47

我来回答

2个回答

热心网友 时间:2022-04-06 03:19

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections.map;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Map;

/**
* A <code>Map</code> implementation that is a general purpose alternative
* to <code>HashMap</code>.
* <p>
* This implementation improves on the JDK1.4 HashMap by adding the
* {@link org.apache.commons.collections.MapIterator MapIterator}
* functionality and many methods for subclassing.
* <p>
* <strong>Note that HashedMap is not synchronized and is not thread-safe.</strong>
* If you wish to use this map from multiple threads concurrently, you must use
* appropriate synchronization. The simplest approach is to wrap this map
* using {@link java.util.Collections#synchronizedMap(Map)}. This class may throw
* exceptions when accessed by concurrent threads without synchronization.
*
* @since Commons Collections 3.0
* @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
*
* @author Stephen Colebourne
*/
public class HashedMap
extends AbstractHashedMap implements Serializable, Cloneable {

/** Serialisation version */
private static final long serialVersionUID = -1788199231038721040L;

/**
* Constructs a new empty map with default size and load factor.
*/
public HashedMap() {
super(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD);
}

/**
* Constructs a new, empty map with the specified initial capacity.
*
* @param initialCapacity the initial capacity
* @throws IllegalArgumentException if the initial capacity is less than one
*/
public HashedMap(int initialCapacity) {
super(initialCapacity);
}

/**
* Constructs a new, empty map with the specified initial capacity and
* load factor.
*
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
* @throws IllegalArgumentException if the initial capacity is less than one
* @throws IllegalArgumentException if the load factor is less than zero
*/
public HashedMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}

/**
* Constructor copying elements from another map.
*
* @param map the map to copy
* @throws NullPointerException if the map is null
*/
public HashedMap(Map map) {
super(map);
}

//-----------------------------------------------------------------------
/**
* Clones the map without cloning the keys or values.
*
* @return a shallow clone
*/
public Object clone() {
return super.clone();
}

/**
* Write the map out using a custom routine.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
doWriteObject(out);
}

/**
* Read the map in using a custom routine.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
doReadObject(in);
}

}

热心网友 时间:2022-04-06 04:37

Map map = new HashMap();
还是你打算自己做一个?追问怎么实现的?

追答看源码吧太长贴不出来 关键是put 和 get 方法的实现
或者你自己做个一类 继承Map 各种Map子类区别的方法你就都知道了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
个人账户养老金预测公式:现有5万元,缴费20年,能领多少钱? 临沂比较有名的男装品牌 呼伦贝尔市悦动网络科技有限公司怎么样? 呼伦贝尔中汇实业有限公司怎么样? 呼伦贝尔油玉不绝电子商务有限公司怎么样? 如何避免wps卡顿? 属鼠的男人找对象是属什么,属鼠的人和什么属相合 96年鼠的姻缘在哪年 属相相合年份运势提升 2024属鼠找对象属什么最佳 黑客攻击网站能报案吗 KENZO高田贤三风之恋 CKFree HUGOBOSS哪款香水适合18岁男生用 最好淡点的吧 要是用HUGOBOSS的话哪款适合 到底什么是哈希值,哈希值到底是怎么生成的,有什么用? 高田贤三是一个怎样的人,业界的口碑如何? $hashkey是怎么添加的 kenzo包包适合哪个年龄段的,还有他们消费水平是怎样的? 几种常见的hash加密,怎么判断hash的类型 中年男性用什么牌子香水比较好(年龄是50岁) 一米八二百斤的胖子图片二十二岁 500斤小伙离世,你认为肥胖的危害有多大? 我是一个500斤的胖子怎么在一年内变成八块腹肌?女网友要见我 这大胖子有多少斤?猜对采纳你 世界上最胖的人是多少斤? 世界上最胖的人有多重? 如何才能成为一个500斤的大胖子? 帐号被永久冻结,怎么办? 图中的男生很胖吗?怎么看出有多重? 图中人胖吗?身高184,体重大概多少? 您的账户涉嫌违反《微信支付用户服务协议》已被永久冻结? 大胖子的图片(文明一点) 目前中国最胖的人大概多少斤? 高田贤三女士香水怎么样,高田贤三女士香水好用吗 hash也就是散列,是为了解决什么问题 ? 根据Hash函数写出Hash表 男生可以用 高田贤三一枝花香水吗? hash join和anti join的区别以及hash join的过程 perl hash表 ++$hash{$strand}{&#39;min1&#39;}{&#39;400ppm&#39;} if $total &gt; 0; 这句话是什么意思呢 Kenzo香水好吗? hash提取元素值 高田贤三风之恋香水 ,一些问题 荒野大镖客hash值 高田贤三风之恋适合什么样的男生使用? 怎么删除hash 高田贤三身高!173体重64公斤适合哪个尺码? perl hash表 $hash{&#39;strand&#39;}[$pos] = $strand 表示什么意思呢? 想买淡雅型女士香水 前端search和hash怎么用 关于php redis的问题 hash结构 正则表达式里的前面加hash表示什么意思 perl中&lt;STDIN&gt;与哈希的问题 nginx 支持一致性hash吗