Finish the 12th day of it 18 Palm Java Foundation Course today:
Learning content:
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
The HashMap and Hashtable are implemented using arrays + linked lists.
The combination of the array of addressing fast, linked list and delete fast features. Use the hash algorithm (hash algorithm) to assign elements to the elements of an array,
Hash partition default 16, each partition is stored in a linked list
1, to calculate the hashcode, &0xof after the four-bit preliminary comparison, determine the partition
2, then compare each object with the list of objects, comparing each object with the same hash code.
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
1. Determine if Hashcode is the same
2. Determine if the same object or equals returns True
So the previous conclusion: HashSet determine whether the element is the same as the element is not independent of the same object is defective, by viewing the source code
We know that the bottom of the HashSet is based on the above method to determine whether the elements are identical.
HashSet the bottom call is HashMap, only concerned about the map key collection
The underlying is an array that stores the linked list objects.
The method of judging whether the object is duplicated is in.
So here we can further summarize the principle of whether the hashset judging elements are identical.
First, judge whether the hashcode is the same, no, two elements do not repeat; Yes, further judgment
Second, whether two objects are the same object, yes, two elements are duplicated (| | Short circuit); no, further judgment
Again, the Eauals method returns True, the two element repeats, returns false, and the two element is not duplicated.
Judgment complete.
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>
II, Collections and Arrays tool class
Problems encountered:
1, HashMap's EntrySet () and Keyset () methods traverse the collection.
2, using the enhanced for loop iteration collection
3, debug use is not skilled,
4, Thread-safe collection vector,hashtable used.
The 5,hash algorithm and the HASHMAP principle are implemented.
Questions that need help
HashMap underlying principle and the difference and connection of HashSet don't understand, not familiar with data structure knowledge
This article from "Rookie Achievement Data Road" blog, reproduced please contact the author!
It 18 Palm Palm 12th Day Course Summary