(i) Collections and arrays
Arrays: (with basic data Types )-a container for the storage object, fixed in length , "not suitable for use with unknown number of objects"
Collection: (The object type can be different)- variable length , which can be used in most cases.
(ii) Hierarchical relationship
1.0: In the figure, the solid line border is the implementation class, the polyline border is an abstract class, and the point line border is the interface:
2.0 Explanation of the collection
①Collection Interface "The root interface " of the "collection class"; There is no direct implementation Class for this interface in Java "----(with two sons)---->
List: ( ordered, duplicated )--(and two sons)--
ArrayList: Underlying data structure---> "dynamic array; thread insecure, high efficiency "---> Query fast, delete and remove slow "move all data".
LinkedList: The underlying data structure---> " linked list; thread insecure, high efficiency "---> Query slow, and delete quickly. "Ideal for BULK Insert , delete data "
Vector: Underlying data structure---> " arrays, thread-safe, inefficient "-query fast, and delete slowly
Set: ( unordered, unique )---> Provides a way to access by index.
HashSet: underlying structure---> " hash table ---dependent->hashcode () and Equals ()"(general rule: Object equals is true, Hashcode needs to be the same, But hashcode the same object is not necessarily equals, this is called the conflict phenomenon, but there are different methods of conflict resolution. If your hashcode () design is good, the conflict will be small. For example, the above-given above the int range after this hashcode () implementation, the object is certainly countless, but the hash implementation is limited, so the conflict. )
TreeSet: underlying structure---> " red-Black Tree ": a self-balancing two-fork tree. Whether the return value is 0-->-uniqueness;
Linkedhashset "orderly, non-repeating": the underlying structure---> " linked list and hash table" lists are guaranteed to be orderly; hash table guaranteed-Unique
②map: ( key value pair, key unique, value not unique ) and collection interface independent, another interface. The--->map contains the key-value pair. the MAP does not duplicate the key, but can have the same value.
HASHMAP: The underlying structure--" hash table, thread insecure, high efficiency --relies on both methods-->hashcode () and Equals () to determine whether to add to the collection"
Hashtable: underlying structure---> " hash table; thread safety efficiency is low "--dependent on the two methods->hashcode () and Equals ()
LINKEDHASHMAP: underlying structure---> " linked list and hash table": The list is guaranteed to be orderly;
TREEMAP: underlying structure---> red black tree return value is 0--> unique
③iterator: All collection classes implement this interface. " traversing interfaces of elements in a collection" Usage:
(1) whether Hasnext () has the next element.
(2) Next () returns the next element.
(3) Remove () deletes the current element.
3.0 comparison of several important interfaces and classes:
Summary of various collections in Java (i)