当前位置:网站首页>Equals increases execution speed / performance optimization
Equals increases execution speed / performance optimization
2022-06-29 11:42:00 【Hard work boy】
In principle, it is close to bron filter .
When you add objects to HashSet when ,HashSet Meeting First calculate the value of the object hashcode value To determine where objects are added , At the same time With other objects that have been added to this location hashcode Comparison of values , If No match Of hashcode,HashSet Meeting Assume that the object does not recur . But if you find It's the same hashcode value The object of , And then it will call equals() Methods to check hashcode Are equal objects really the same . If The two are the same ,HashSet It won't make the join operation successful . If it's different , It will be re hashed to other locations .
public class test1 {
public static void main(String[] args) {
String a = new String("ab"); // a For a quote
String b = new String("ab"); // b For another reference , Object has the same content
String aa = "ab"; // Put in constant pool
String bb = "ab"; // Find from constant pool
if (aa == bb) // true
System.out.println("aa==bb");
if (a == b) // false, Not the same object
System.out.println("a==b");
if (a.equals(b)) // true
System.out.println("aEQb");
if (42 == 42.0) // true
System.out.println("true");
}
}
This greatly reduces equals The number of times , Accordingly, the execution speed is greatly improved . We can see from it that : hashCode() Its function is to get hash code , Also known as hash code ; It actually returns a int Integers . The function of this hash code is to determine the index position of the object in the hash table .hashCode() Only useful in hash tables , In other cases it doesn't work . In the hash table hashCode() Is used to get the hash code of an object , Then determine the position of the object in the hash table .
边栏推荐
- 安全 创新 实践|海泰方圆受邀参加“数字时代的网信创新与价值共创”技术交流研讨会
- [HBZ sharing] InnoDB principle of MySQL
- 毕业5年,我问遍了身边的大佬,总结了他们的学习方法
- 稳定币风险状况:USDT 和 USDC 安全吗?
- Pipeline aggregations管道聚合-Sibling-1
- How to test the performance of container platform, including stability, expansion efficiency and component performance
- 【HBZ分享】Mysql的InnoDB原理
- Course design for the end of the semester: product sales management system based on SSM
- MySQL 索引失效的几种类型以及解决方式
- Haitai Advanced Technology | application of privacy computing technology in medical data protection
猜你喜欢
![Leetcode 535 encryption and decryption of tinyurl [map] the leetcode road of heroding](/img/76/709bbbbd8eb01f32683a96c4abddb9.png)
Leetcode 535 encryption and decryption of tinyurl [map] the leetcode road of heroding

Qt学习01 GUI程序原理分析
![[NLP] text generation topic 1: basic knowledge](/img/cf/2e29e55344ea4cc8ce48777878b867.png)
[NLP] text generation topic 1: basic knowledge

Cornerstone of efficient remote office: effective communication | community essay solicitation

What is the experience of working in an IT company in Japan?

XML external entity injection vulnerability (I)

Modbus RTU protocol 485 learning 2-way infrared module

信息技术应用创新专业人员(数据库)中级培训火热招生中(7月6-10日)

Discussion on QT learning 10 message processing in QT

The first "cyborg" in the world died, and he only transformed himself to "change his life against the sky"
随机推荐
Week 12 experiment -- implementation of VGA protocol based on FPGA
微博评论架构设计
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
XML external entity injection vulnerability (I)
又拍云 Redis 的改进之路
又拍雲 Redis 的改進之路
Follow Me Study HCIE-Big Data-Data Mining 第一章 数据挖掘介绍 模块一
【高并发】2.8万字的Callable和Future面试知识点总结,看完我直接面进了字节跳动,原谅我有点飘了(上)
【HBZ分享】Semaphore 与 CountDownLatch原理
稳定币风险状况:USDT 和 USDC 安全吗?
(JS) handwritten bind function
Nature | 全球海洋微生物组的生物合成潜力
Oracle扩充分布式云端服务 为更多客户带来全面公有云服务
How to test the performance of container platform, including stability, expansion efficiency and component performance
Qt学习11 Qt 中的字符串类
The former security director of Uber faced fraud allegations and concealed the data leakage event
Qt学习06 窗口部件及窗口类型
Modbustcp protocol WiFi wireless learning single channel infrared module (small shell version)
MySQL开启慢查询
Nature | biosynthetic potential of global marine microbiome