Java --- container summary, java --- container Summary
Java provides a large number of ways to hold objects:
(1)Array associates numbers with objects. It stores objects with clear types. You do not need to convert the result type when querying objects. It can be multidimensional and can save basic data types. However, once an array is generated, its capacity cannot be changed.
(2) CollectionSaves a single element, while Map stores the associated key-value pairs. With JavaGenericYou can specify the object type stored in the container, so you will not place the error type objects in the container, and do not need to perform type conversion when getting elements from the container. Various collections and various maps can be automatically adjusted when you add more elements to them. The container cannot hold the basic type, but the automatic packaging mechanism will perform a two-way conversion between the basic type and the package type held in the container carefully.
(3)Like an array,ListIt also establishes the association between the numeric index and the object. Therefore, arrays and lists are sorted containers. List can automatically expand the capacity.
(4)UseArrayList(Array features)If you want to insert or delete elements from the table frequently, useShortlist(With the characteristics of linked list)
(5)VariousQueue(Queue) and stack behaviorShortlistProvide support.
(6) MapIt is a design that associates objects (rather than numbers) with objects.HashMapDesigned for fast access, whileTreeMapKeep the "key" in the sorting state, so noHashMapFast.LinkedHashMapThe element insertion sequence is maintained, but the fast access capability is also provided through the hash.
(7) SetDuplicate elements are not accepted. HashSet provides the fastest query speed, while TreeSet keeps elements in order.
LinkedHashSetSave elements in the insert sequence.
Java container diagram (excluding abstract classes and legacy components ):
|
As you can see, there are actually only four types of containers:Map,List,SetAndQueue, Each of which has two to three implementation versions. Commonly used containers are displayed in a black rough box.
The dotted box represents an interface, and the solid box represents a common (specific) class. A dot line with a hollow arrow indicates that a specific class implements an interface, and a solid arrow indicates that a class can generate an object pointed to by an arrow. For example CollectionGenerateIterator, AndListGenerateListlterator(CommonIteratorBecause List inherits fromCollection)
Java containers use tools every day, which can make programs more concise, larger, and more efficient. |
|
1. Java container Overview
2. Java container-Basic Concepts
3. Java container --- Collection Interface
4. Java container --- Arrays & Collections tool class
5. Java container --- character container StringBuffer & StringBuilder
6. Java container --- basic List
7. java container --- Comparable & Comparator
8. Java container --- Set basics: HashSet & TreeSet & LinkedHashSet
9. Java container --- iterator
10. Java container --- Map Basics