当前位置:网站首页>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 .
边栏推荐
- IDEA中文棱形乱码错误解决方法--控制台中文输出棱形乱码
- Chapter I linear table
- Global and Chinese market for commercial ceiling fans 2022-2028: Research Report on technology, participants, trends, market size and share
- < 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(六)
- (四)GoogleNet複現
- TS 22.011
- Global and Chinese markets of automatic glue applicators 2022-2028: Research Report on technology, participants, trends, market size and share
- Divide training set, test set and verification set
- Example of bit operation (to be continued)
- Keep an IT training diary 067- good people are grateful, bad people are right
猜你喜欢

RTOS rt-thread裸机系统与多线程系统

同源?跨域?如何解决跨域?

Great God cracked the AMD k6-2+ processor 22 years ago and opened the hidden 128KB L2 cache

Project training of Software College of Shandong University rendering engine system basic renderer (III)

Axure RP 9 for MAC (interactive product prototyping tool) Chinese version

Five models of software testing
![In 2020, the demand for strain sensors in China will reach 9.006 million, and the market scale will reach 2.292 billion yuan [figure]](/img/a8/dd5f79262fe6196dd44ba416a4baac.jpg)
In 2020, the demand for strain sensors in China will reach 9.006 million, and the market scale will reach 2.292 billion yuan [figure]

acwing 802. 区间和 (离散化)

2022.02.28 - SX11-05. The largest rectangle in the histogram

Redis General Command
随机推荐
(四)GoogleNet复现
PHP builds a high-performance API architecture based on sw-x framework (II)
Step by step to create a trial version of ABAP program containing custom screen
【架构优化过程思考】如何构建技术方案影响的评估能力
Task fruit Juicer 0611
Defer learning in golang
Escape rules and examples of go
Solution to idea Chinese prism garbled code error -- console Chinese output prism garbled code
【周赛复盘】LeetCode第80场双周赛
acwing 798二维差分(差分矩阵)
Unity get local video / download network video
acwing 803. 区间合并
一步步创建包含自定义 Screen 的 ABAP 程序的详细步骤
线程池执行流程
Tensorflow function: tf nn. in_ top_ k()
面试:什么是浅拷贝、深拷贝?
Global and Chinese markets for air sampling calibration pumps 2022-2028: Research Report on technology, participants, trends, market size and share
从斐波那契数列求和想到的俗手、本手和妙手
Decision tree classification and examples
tinyint和int区别