The Java Collection class is primarily responsible for storing and holding data, so the collection class is also called the container class. Before you know collection, there are three concepts to distinguish between:
1. Collection collection, used to represent any data structure;
2. Collection Collection interface, refers to the Java.util.Collection interface, is a set, list and queue interface of the super-class interface;
3. Collections Collection Tool class, refers to the Java.util.Collections class。 The set referred to here refers to the lowercase collection, the collection has 4 basic forms, where the first three classes of the parent interface refers to collection.
1.Set focuses on the uniqueness of things, representing unordered, non-repeatable collections;
2.List An indexed list of things that represent an ordered, repeatable set;
3.Queue focuses on the order in which things are processed, representing the queue collection;
4.MAP focuses on the mapping of things and the uniqueness of key values, representing a set of mappings;
The Java Collection class is primarily derived from two interfaces: collection and map, which are the root interfaces of the collection framework. The following is an inheritance tree of its interfaces, interfaces, and implementation classes.
First, Collection interface
The collection interface is the parent interface of the set, List, and Queue interfaces, and provides a common method declaration for most collections, including add (), remove (), contains (), size (), iterator (), and so on.
1. List interface
The list is concerned with indexes, which are specific to the index, compared to other collections: Get (int index), add (int index,object o), indexOf (Object o).
ArrayList can interpret it as an array of growth that provides fast iterations and the ability to quickly random access.
The elements in the LinkedList are double-linked, and LinkedList becomes the perfect choice in the list when quick insertions and deletions are required.
Vector is a thread-safe version of ArrayList, which has a lower performance than ArrayList and is now rarely used
2. Set interface
Set cares about uniqueness, it does not allow duplication.
HashSet You can use this class when you do not want duplicate values in the collection, and you do not care about the order between elements.
Linkedhashset This class when you do not want duplicate values in the collection, and you want to iterate through the elements in the order in which they are inserted.
TreeSet can take this class when you do not want duplicate values in the collection and want to sort by the natural order of the elements. (Natural order means something that is not related to the insertion order, but rather to the ordering of the content and attributes of the element itself, such as "ABC" in front of "Abd"). )
3. Queue interface
The queue is used to save the list of tasks that will be performed.
The LinkedList also implements the queue interface, which enables FIFO-first queues.
priorityqueue is used to create a priority queue for natural sorting.
Second, MAP interface
The common methods for map interfaces are shown in the following table:
Because the keys in the map must be unique, the key can be null, only one key is null, and the value in map does not have this restriction, and a value of NULL is often present, so the get (Object key) method returns NULL, There are two cases in which the key value pair does not exist, and the value object that corresponds to the key is null. To ensure that a key is actually in a map, the method you should use is ContainsKey (Object key).
1.Map interface
Map is concerned with the unique identifier. He maps the unique key to an element. Of course, the keys and values are objects.
HashMap When a key-value pair is required and the order is not concerned, HASHMAP can be used.
Hashtable Note that T in Hashtable is lowercase, it is a thread-safe version of HashMap and is now rarely used.
Linkedhashmap can be used when a key-value pair is required and is concerned about the insertion order.
TreeMap can be used when a key-value pair is required and is concerned about the natural ordering of the elements.
Original address: http://blog.csdn.net/zzp_403184692/article/details/7677821
Summary of Java collection classes