According to the idea of Java programming, the Java collection is also called a container, which is divided into two categories, collection and map, in terms of single and double slots, both of which are interfaces.
First, Collection
Collection below is divided into three sub-interfaces, namely Set,list and queue, respectively, their characteristics are:
1.Set: The element is unique, that is, the elements in the set can never be duplicated, as is the concept of a set in mathematics. All of its implementation classes have the same characteristics.
There are three main implementation classes: Hashset,linkedhashset,treeset
- The underlying implementation of HashSet is the key in the HashMap, so it is characterized by disorder and non-repetition;
- The Linkedhashset bottom implementation is linkedhashmap, characterized by the elements becoming orderly. Here the order refers to the same traversal sequence and the insertion order.
- TreeSet the underlying implementation is TREEMAP, is also ordered, here the order refers to the size of the element itself, for the integer, String, itself has implemented the comparable interface, so they are comparable. Developer-defined objects require their own implementation of the comparable interface to facilitate program execution of element comparisons.
2.List: Ordered, the List is ordered and repeatable, and here the order is only the same as the traversal sequence and the insertion order. The most common implementation classes:
- ArrayList bottom implementation is an array, so the query efficiency is high, and the efficiency is low;
- LinkedList bottom implementation is linked list, longer than insert Delete, query efficiency is low.
3.Queue: Queue, characterized by FIFO, only allow deletion in front of queue, queue back-end insertion, commonly implemented class Priorityqueue.
Second, Map
If arrays and lists implement mapping of subscript and element objects, then map implements the mapping between objects and objects.
Main implementation classes: Hashmap,linkedhashmap and TreeMap
A hash table is used at the bottom of the HashMap to enable quick lookups.
The most important feature of Linkedhashmap is that the key value is ordered, and the traversal order is the same as the insertion order.
The bottom of the treemap is a red-black tree, and the newly inserted elements are compared to the elements in the map and inserted into the inserted position. The TreeMap object must implement the comparable interface.
Java Collection Framework collection (3)