Shows a complete diagram of the Java Container Class library, including abstract classes and legacy artifacts (excluding queue implementations).
The commonly used container is represented by a thick black wireframe, a dotted box represents an interface, a dashed box represents an abstract class, a solid wireframe represents a class, and a hollow arrow represents an implementation relationship. Produce indicates that arbitrary map objects can generate collection objects, and arbitrary collection objects can generate iterator objects.
Finally, we summarize the list, Set, map interface and the characteristics of each implementation class in tabular form:
|
Characteristics |
Implementation class |
Implementing Class Attributes |
Requirements for placed elements |
List |
Linear, ordered storage container with index access to element get (n) |
ArrayList |
Array implementations. Non-synchronous. |
|
Vector |
Similar to ArrayList, synchronous. |
|
LinkedList |
Doubly linked list. Non-synchronous. |
|
Set |
element cannot be duplicated, element must define equals () method |
HashSet |
Set for quick Find design |
element must be defined hashcode () |
TreeSet |
The set of the hold order, the bottom is the tree structure |
Element must implement comparable interface |
Linkedhashset |
Internal use of the chain list to maintain the order of elements (inserted order) |
element must be defined hashcode () |
Map |
To save a key-value pair member, all keys in the map must define the Equals () method |
HashMap |
The implementation of MAP interface based on hash table to meet the common requirements |
The key must have the appropriate hashcode (), and if you modify the Equals method, you need to modify the Hashcode method |
TreeMap |
Sort by default according to natural order, or sort according to the comparator provided when the mapping is created |
Key members require implementation of the Caparable interface, or use comparator to construct treemap. Key members are generally of the same type. |
Linkedhashmap |
Similar to HashMap, but the order in which "key-value pairs" are obtained when iterating through is the order in which they are inserted or least recently used |
Same as HashMap |
Identityhashmap |
Hash map to compare "key value" with = = instead of equals () |
Members are judged equal by = = |
Weakhashmap |
Weak key mapping, which allows you to release the object that the map points to |
|
Concurrenthashmap |
Thread-Safe Map |
|
(1) The behavior of various queue and stack can be fully supported by LinkedList, the above table does not contain a queue.
(2) But any hash-related, it will inevitably be designed to the Hashcode method, because the return of the hash code to calculate the position of the object in the hash table, but the general and tree-related, will inevitably design to the comparable interface, because it involves sorting.
(3) If you want to do a lot of random access, is to use ArrayList, if you want to frequently insert or delete elements from the middle of the table, you should use LinkedList. When traversing, for ArrayList preference get mode, LinkedList preferred iterator mode.
(4) collection inherits the Iterable interface, so all collection objects can iterate through the elements using the Foreach method. All collection objects Hiuforeach loops can work with any object that implements the Iterable interface.
Java Container Tour: Container Basics Summary