对HashMap的一次记录

HashMap的具体学习,认识了解。


前言

也是最近开始面试才发现,HashMap是问的真多。以前听学长或自己在网上看到过一些面试资料都在说集合、线程这块比较重要,面试的重点。自己也是有那抵触情绪,所以自认为这块不重要,但最终发现自己真的太狭隘了,Map这块的知识真的是对数据存储有一个新的认识。但我现在认识尚浅,所以也真的说不出来什么感悟。只能就是对这块来一个简单的入门吧(主要原因还是自己的不注重基础知识的回顾,和一些重点源码的学习,导致时间一长,啥也不知道!)。
希望写完这篇随笔可以让自己对这块知识有个逻辑层次的认识。


一、回顾复习

1、Hash(哈希)是什么?

Hash,一般翻译做散列、杂凑,或音译为哈希,是把任意长度的输入(又叫做预映射pre-image)通过散列算法变换成固定长度的输出,该输出就是散列值。这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间,不同的输入可能会散列成相同的输出,所以不可能从散列值来确定唯一的输入值。简单的说就是一种将任意长度的消息压缩到某一固定长度的消息摘要的函数 —引自百度百科


2、Map是什么?

首先将它意思翻译过来是“地图”“了解信息”的意思;当然在Java中可以理解为“映射”;
Map它是Java提供的专门用来存放“键值对”这种形式对象的接口;可以把它认为也是一个集合框架。
下面这个图真的见的很多很多,但却是简单明了的了解Java集合的好方法。
image


3、HashMap是什么?

Tips:Map接口中的集合都有两个泛型变量<K,V>,在使用时,要为两个泛型变量赋予数据类型。两个泛型变量<K,V>的数据类型可以相同,也可以不同

从维基百科中可以看到(我是直接用的谷歌翻译)

In computing, a hash table (hash map) is a data structure that implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index, also called a hash code, into an array of buckets or slots, from which the desired value can be found. During lookup, the key is hashed and the resulting hash indicates where the corresponding value is stored.
Ideally, the hash function will assign each key to a unique bucket, but most hash table designs employ an imperfect hash function, which might cause hash collisions where the hash function generates the same index for more than one key. Such collisions are typically accommodated in some way.
In a well-dimensioned hash table, the average cost (number of instructions) for each lookup is independent of the number of elements stored in the table. Many hash table designs also allow arbitrary insertions and deletions of key–value pairs, at (amortized[2]) constant average cost per operation.[3][4]
In many situations, hash tables turn out to be on average more efficient than search trees or any other table lookup structure. For this reason, they are widely used in many kinds of computer software, particularly for associative arrays, database indexing, caches, and sets.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值