Summary of collection and generics collation in Java
There are three main types of collections used in Java: List, set, Map;
Implementation of the interface Collection are: List, Set;
List,
The list interface implements the following three types of implementations: ArrayList : Dynamic array LinkedList : An efficient set of vectorsdesigned for frequent insertion or deletion of intermediate elements: dynamic arrays, synchronized, Thread-Safe
More commonly used is the ArrayList array, but the ArrayList will appear duplicate elements, and there is no way to sort, need to rely on the Collections class sort () method;
The parameters of Collections.sort () need to meet certain conditions;
public static <t extends Comparable<? Super t>> void Sort (list<t> List);
public static <T> void sort (list<t> List, comparator< super t> C)
So for the elements in the set, you must implement the CompareTo method in the comparable interface, or define a class that implements comparator;
As can be seen from the definition, as long as the implementation of the list interface can be sorted in this way. Set: There are no duplicate elements in the collection
There are several implementation classes for set interfaces:
hashset: linkedhashset: TreeSet: orderly;
For the set set, the mechanism of checking repetition is mainly used in Hashcode and Equels methods.
You can override the two methods for the elements in the collection to achieve the effect of validation duplicates.
TreeSet will sort the elements, we know that when we encounter the sort, the elements in the collection need to implement the comparable interface CompareTo () method, or create comparator with a constructor with a TreeSet parameter TreeSet.
Map TreeMap HashMap linkedhashmap Hashtable
The map is primarily accessed in the form of key-value pairs.
Generic type
Public <t extends animal> void takething (arraylist<t> list) public
void Takething (ArrayList (? extends Animal> list)