"One Minute Knowledge" HashSet and Treeset,hashmap and Hashtable
HashSet and TreeSet
HashSet
Hash table is implemented, the data in the HashSet is unordered.
There is no guarantee that the order of the elements may change.
It's not synchronized.
The collection element can be null but can only be placed in a null
When an element is deposited into the HashSet collection, HashSet calls the object's Hashcode () method to get the Hashcode value of the object, and then determines where the object is stored in Hashcode according to the HashSet value.
TreeSet
Binary tree implementation, the data in the TreeSet is automatically sorted, not allowed to put null values
TreeSet is the only implementation class for the SortedSet interface, and TreeSet ensures that the collection elements are in a sorted state.
TreeSet supports two sorting methods, natural sorting and custom sorting, where the natural sort is the default sort.
The object to be added to the treeset should be the same class.
TreeSet that two objects are not equal is two objects return false through the Equals method, or they do not return 0 through the CompareTo method comparison.
HashMap and Hashtable
HashMap
Thread not secure
Allow null keys and values to be more efficient
The method is not synchronize.
To provide external synchronization there are containsvalue and ContainsKey methods
HashMap is an implementation of map interface introduced by Java1.2
HashMap is a lightweight implementation of Hashtable
HashTable
Thread Safety
Null keys and values are not allowed
A little less efficient
Method is a contains method of synchronize
Hashtable inherits from the dictionary class,
Hashtable is older than HashMap.