equlas and HashCode, equals and ==

Recent problems in processing large amounts of data View List, the forum was suggested two solutions, I feel it more reliable

1. 1,000,000 these data, through broken into smaller data hash, then the number of repeating necessarily in the same data block, then the establishment of a plurality of threads, each process a block of data, each of the first data block ordering, then binary search.

2. Because the more one million data, you can use a map to process the data, key data, the value is the number of the data presented, if one million of fixed data, you can consider using bitmap but only among java bitset, so bitmap only themselves to emulate, and then quickly look through the map.

The original site https://bbs.csdn.net/topics/391815755

For HashCode unfamiliar, so the following records

We must first clear a knowledge hashCode equal, equals may not be equal, but equals are equal, then it must equal hashCode these two theorems! This is the norm for most applications, there are exceptions of course, certainly outside the norm.

Secondly, we also understand that a knowledge HashCode and equlas relationship:

(1) If you do not create a "class corresponding hash table, then" (that is, when we do not put in place a class HashSet, Hashtable, HashMap that is the underlying implementation hashcode storage location, then come and positioning), if this is not the case, then, when this class hashcode () and equals () is nothing to do in the

(2) If you happen to use the above mentioned "Creating a class corresponding hash table," and then you put this class is key to come and go as stored value other words, this case can be compared

Explanation:

User user1=new User();
User user2=new User();

Map<User,String> map=new HashMap<User,String>();

map.put (user1, "This is user1" );

map.put (user2, "This is user2" );

The User class HashCode Equals and have a relationship. If this is not the case of storage, they are not related to them

Original link: https: //blog.csdn.net/qq_36520235/article/details/84679541

If two objects are equal, then their hashCode () values be the same. Here means equal, returns true if two objects by comparing equals ().
If two objects hashCode () are equal, they are not necessarily equal.
Because in the hash table, the hashCode () are equal, the hash value that is equal to two key-value pairs. However hash values are equal, not necessarily draw key-value pairs are equal. Added the sentence: "Two different key-value pairs, equal hash value," which is a hash conflict. (To determine whether two objects are equal, in addition to covering the equals (), but also on covering hashCode () function. Otherwise, equals () is invalid.)

equas and ==

First of all to clear all equals and == Object superclass method

When we create a new entity class is going to be the successor of two methods.

In the superclass equals and == it is relatively the same for the address of the object.

In practice then, most people are rewritten in the new entity class equals () method is used to compare the contents of the object,

For example, we used the String, String of equals is to be rewritten, so when the two strings are the same, it will return true.

 

The last thing clear to super class Object equals and == for comparison are the same as the address, and in the entity classes that you create, you need to look at whether to rewrite equals () method

 

Guess you like

Origin www.cnblogs.com/cyc-ghost/p/12066011.html