Today again review Java Collection class, compared to the previous study, there are a lot of gains, but also remember the brain inside, or to insist on blogging for the sake of.
To get to the point, the first thing is to make it clear that collection and collections,collection are the parent interfaces of List,set and queue interfaces, and collections is a tool class for manipulating collections.
The knowledge of the collection system is as follows:
First of all, set set: Set set is similar to a honeypot, you can throw multiple objects in, and set can not remember the order of adding elements. The set set is basically the same as collection, no additional method is provided, or set is collection. If the Add () element is the same, the flase is returned and the addition fails.
Hashset:hashset stores the elements in the binding according to the hash algorithm, thus having good access and lookup performance.
Linkedhashset: Use a table to maintain elements, because the insertion order of elements needs to be maintained, so performance is slightly lower than hashset.
TreeSet: The data structure of the red-black tree is used to store the collection elements and supports two sorting methods, natural sorting and custom ordering. Note: When using TreeSet, the added objects are guaranteed to implement the comparable interface, otherwise the failure is added and a Classcastexecption exception is thrown. In a nutshell, if you want TreeSet to work properly, you can only add objects of the same type.
Enumset: The collection class that is designed for the enumeration class. The interior is stored as a vector, and the storage form is very compact, and all enumset are small in memory and efficient in object use.
Each set implements class performance analysis: HashSet performance is always higher than treeset, if you want to keep the ordered set, use TreeSet. Linkedhashset is slightly slower than hashset for normal insert deletions, but with a table, traversing Linkedhashset is faster and Enumset is the best performance in a set implementation class, but only elements of the same type can be saved. And all of the set implementation classes are thread insecure.
Reference: Uncle Li's "Crazy Java Handout"
Java Collection-(set)