Two interfaces are inherited from collection.
List (Inteface)
Order isThe most important feature of List is that it ensures that elements are maintained in a specific order.
--arraylist allows fast random access to elements.
--linkedlist is optimized for sequential access toThe cost of the middle insertion and removal of the List is small, with addfrist (), AddLast (), Getfirst,getlast,removefirst, and Removelast (). These methods allow LinkedList to be used as a stack/queue/bidirectional queue.
Set (Inteface)
Each element that is stored in the set must be unique and does not guarantee the order in which the elements are maintained. Object that joins set must define the Equals () method
--hashset set designed for quick Find , the HashSet object must be defined Hashcode ().
The set of the--treeset protection Order , which can be used to extract ordered sequences from the set.
The--linkedhashset has a hashset query speed and internally uses the chain list to maintain the order of elements.
They are not stored the same way:
TreeSet uses a tree of red-and-black trees to sort elements of the structure.
HashSet uses hash functions, which are specifically designed for fast queries.
Linkedhashset internally uses hashing to speed up queries, while maintaining the order of elements using a linked list.
When using Hashset/treeset, you must define equals () for the class, and Hashcode () is for HashSet, which, as a programming style, should overwrite the hashcode () at the same time as the Equals ().
The relationship and difference between set and list in Java