当前位置:网站首页>Simple understanding of why to rewrite hashcode and equals methods at the same time
Simple understanding of why to rewrite hashcode and equals methods at the same time
2022-06-29 22:10:00 【Wait for the wind】
Knowledge point :
1. If two objects use equals Unequal , be hashcode Must be different
Why?
Because love .
We know set Collections do not allow duplicate elements , How can we ensure that there is no repetition . use equals The method is enough . But once there's a lot of data , When that object is compared with the objects in the collection , Call... Every time equals Method , and equals The method is realized by == Realized , Compare addresses , The address can only be obtained by accessing the bottom layer , So the line efficiency is low .
How to solve it ? Is to rewrite hashcode Method , and hashcode It's self generated , No access to the underlying , This can be viewed String Source code ,
Every time I compare , Compare first hashCode, If it's not equal , Then there's no need to compare , Go straight back to false, If equal , I call again equals Methods for comparison , This improves efficiency .
边栏推荐
- R language plot visualization: plot visualization box graph and several box plots of multiple classification variables
- Information available from radar echo
- Flame retardant test of aluminum sheet as/nzs 1530.1 non combustible materials
- How do new shareholders open accounts online? Is it safe to open an account online?
- 华为7年经验的软件测试总监,给所有想转行学软件测试的同学的几个建议
- A. Print a Pedestal (Codeforces logo?)
- Getting started with completabilefuture
- Which brokerage commission is the lowest and safest
- Graduation summary of construction practice camp
- Visual analysis and display effect of summer data
猜你喜欢

cout 不明确问题

Golang operation NSQ distributed message queue

生产环境AIX小机报错B6267342问题处理

Win10 add SSH public key

Redis (I) -- getting started with redis (1) -- redis introduction, installation and startup, and common configurations

Viewing technological changes through Huawei Corps (V): smart Park

Huawei cloud AOM version 2.0 release

尚硅谷实时数据仓库项目(阿里云实时数仓)

一文2500字手把手教你使用jmeter进行分布式压力测试【保姆级教程】

American tunneling ASTM E84 surface flame retardant test
随机推荐
亚马逊关键词搜索API接口(item_search-按关键字搜索亚马逊商品接口),亚马逊API接口
亚马逊商品详情API接口-(item_get-获得AMAZON商品详情接口),亚马逊详情API接口
硅树脂油漆申请美国标准UL 790 Class A 合适吗?
数论-整除分块
LeetCode 1. Sum of two numbers
尚硅谷实时数据仓库项目(阿里云实时数仓)
美国隧道法ASTM E84 表面阻燃测试
STM32 minimum system construction (schematic diagram)
阿里巴巴商品详情API接口(item_get-获得商品详情接口),阿里巴巴API接口
Sophon CE community edition goes online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
证券开户选择哪个证券另外想问,现在在线开户安全么?
阿里巴巴关键字搜索商品API接口(item_search-按关键字搜索商品接口),阿里巴巴搜索API接口
If the evaluation conclusion of waiting insurance is poor, does it mean that waiting insurance has been done in vain?
DevCloud加持下的青软,让教育“智”上云端
细说GaussDB(DWS)复杂多样的资源负载管理手段
小型圖書館項目總結
阿里巴巴店铺的所有商品API接口(item_search_shop-获得店铺的所有商品接口),阿里巴巴API接口
软件快速交付真的需要以安全为代价吗?
Writing a makefile for a golang project
jfinal中如何使用过滤器监控Druid监听SQL执行?