---------- Android training, Java training, and hope to communicate with you!
----------
Comparison of hashset and analysis of hashcode
- Hashset implements the set interface, which is supported by the hash table. It does not guarantee the set iteration sequence; in particular, it does not ensure that the sequence remains unchanged. This class is allowed
NullElement.
- Hashcode in Java, the hash code represents the characteristics of an object. Hash code generation basis: the hash code is not completely unique. It is an algorithm that allows objects of the same class to have different hash codes according to their own characteristics, but it does not indicate that the hash codes of different objects are completely different. The same is true for programmers who want to write hash code algorithms. The following describes three common hash algorithms. 1: hashcode of the object class. The structure of the memory address of the returned object after processing. Because the memory address of each object is different, the hash code is also different. 2: hashcode of the string class. According to the content of the string contained in the string class, a hash code is returned based on a special algorithm. As long as the string content is the same, the returned hash code is also the same. 3: For the integer class, the returned hash code is the value of the integer contained in the integer object. For example, integer I1 = new INTEGER (100) and i1.hashcode is 100. It can be seen that two integer objects of the same size return the same hash code.
The following is an example:
String str1 = "AA", str1.hashcode = 3104 string str2 = "BB", str2.hashcode = 3106 string str3 = "AA", str3.hashcode = 3104
According to hashcode, str1 can be obtained! = Str2, str1 = str3 so when you create an object, because you change the value of the object, the hash value of the object will be changed. If you delete this object, in fact, you deleted the hash value you modified later. The Hash Value of the previous object still exists in the memory, leading to memory leakage.