In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to understand hashCode () in java". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand hashCode () in java".
1. The function of hashCode is to get hash codes, also known as hash codes, which actually return int integers. The purpose of the hash code is to determine the index position of the object in the hash table.
2. HashCode is defined in the Object class of JDK, which means that any class in Java contains hashCode functions.
Example
Package com.tools; import java.util.ArrayList; public class HashCodeMeaning {public static void main (String [] args) {ArrayList list = new ArrayList (); int numberExist=0; / / proves that the value of hashcode is not the memory address for (int I = 0; I < 10000; iTunes +) {Object obj=new Object () If (list.contains (obj.toString () {System.out.println (obj.toString ()) + "exists in the list. "+ I); numberExist++;} else {list.add (obj.toString ());}} System.out.println (" repetition number: "+ numberExist); System.out.println (" list size: "+ list.size ()); / / prove that the memory address is different. NumberExist=0; list.clear (); for (int I = 0; I < 10000; iTunes +) {Object obj=new Object (); if (list.contains (obj)) {System.out.println (obj + "exists in the list. "+ I); numberExist++;} else {list.add (obj);}} System.out.println (" repetition number: "+ numberExist); System.out.println (" list size: "+ list.size ()) }} Thank you for your reading. The above is the content of "how to understand hashCode () in java". After the study of this article, I believe you have a deeper understanding of how to understand hashCode () in java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 258
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.