当前位置:网站首页>Interview: hashcode() and equals()
Interview: hashcode() and equals()
2022-06-12 16:11:00 【Sleepless autumn rain】
Q:hashCode() What's the usage? ?
hashCode() yes Object Class , Returns the hash value of the object , Used to determine the index position of the object in the hash table .
Q:hashCode() How to use it? ?
When inserting data into a hash table , The hash value of the object will be calculated first to determine the insertion location , If the position is without elements , Then the direct insertion succeeds . If there are elements , Hash table will utilize equals() Method to compare with the element at that location . If the element to be inserted is related to equals() return true, So insert failed , If you return false, Then the hash table will hash it to other locations or use the zipper method to add it .
Q: Why? java To provide these two methods ?
Because of the hashcode(), It is more efficient to judge whether the elements are equal .
Q: Why rewrite equals() To rewrite hashcode()?
Guarantee equals() return True when hashcode() Also equal . If you do not override , There may be a equals() return true, But two objects hashcode() Unequal .
边栏推荐
- Global and Chinese markets of three-phase induction motors 2022-2028: Research Report on technology, participants, trends, market size and share
- Redis string type common commands
- [automation] kolla Based Automated Deployment CEPH cluster
- Axure RP 9 for MAC (interactive product prototyping tool) Chinese version
- 面试:‘==‘与equals()之间的区别
- Great God cracked the AMD k6-2+ processor 22 years ago and opened the hidden 128KB L2 cache
- acwing 797 差分
- [tool recommendation] personal local markdown knowledge map software
- 作业提交说明 上传作业到网盘中
- Escape rules and examples of go
猜你喜欢

一步步创建包含自定义 Screen 的 ABAP 程序的详细步骤试读版

C language partition bin file program

Classic case of solidity - Smart games

Introduction and download website of common data of GIS, remote sensing, hydrology and Geography (2), supplementary~
![Analysis of global and Chinese shipbuilding market in 2021: the global shipbuilding new orders reached 119.85 million dwt, with China, Japan and South Korea accounting for 96.58%[figure]](/img/3e/b54b7f15c4a6326d8c7c4433388a3a.jpg)
Analysis of global and Chinese shipbuilding market in 2021: the global shipbuilding new orders reached 119.85 million dwt, with China, Japan and South Korea accounting for 96.58%[figure]

acwing788. 逆序对的数量

IDEA中文棱形乱码错误解决方法--控制台中文输出棱形乱码

Solution to idea Chinese prism garbled code error -- console Chinese output prism garbled code

The common hand, the original hand and the excellent hand from the sum of Fibonacci sequence

From K-means to capsule
随机推荐
Decision tree classification and examples
读取mhd、raw图像并切片、归一化、保存
Redis string type common commands
acwing 790. 数的三次方根(浮点数二分)
Go Net Library (to be continued)
redis String类型常见命令
< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(七)
How to use grafana to easily realize OVL data visualization
MYSQL---服务器配置相关问题
Global and Chinese market for commercial ceiling fans 2022-2028: Research Report on technology, participants, trends, market size and share
UE4 常用类型转换
Global and Chinese market of soft capsule manufacturing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Reprise de Google net
acwing 801. 二进制中1的个数(位运算)
Match single character
Redis General Command
MySQL blob and text types
5g new scheme! Upgrade the existing base station and UE simulator to 5g millimeter wave band
Task fruit Juicer 0611
acwing 802. 区间和 (离散化)