1: Set Collection (Single column collection) List (ordered, repeatable) ArrayList The underlying data structure is an array, query fast, delete slow thread unsafe, efficiency High Vector underlying data structures are arrays, fast queries, additions and deletions slow thread safety, low efficiency linkedlist the underlying data structure is the chain Table, query slow, delete fast thread unsafe, high efficiency Set (unordered, unique) HashSet the underlying data structure is a hash table. The hash table relies on two methods: Hashcode () and Equals () execution order: first determine whether the hashcode () value is the same: Continue execution equ ALS (), see if its return value is true: The description element is duplicated, not added is false: added directly to the collection No: Add directly to the collection final: Automatically generate Hashcode () and Equals () to Linkedhashse The underlying data structure consists of a linked list and a hash table. The chain list guarantees an orderly element. The element is guaranteed to be unique by a hash table. TreeSet the underlying data structure is a red-black tree. (is a self-balancing two-fork tree) How to guarantee the uniqueness of the element? Determines how the elements are ordered, based on whether the return value of the comparison is? Two different ways Natural ordering (the element is comparative) enables the class to which the element belongs implements the comparable interface comparer sort (collection with comparison) Let the collection receive a comparator implementation class object Map (Double column collection) The data structure of the A:map collection is only valid for the key, regardless of the value. B: The elements stored in the form of a key-value pair, the key is unique, and the value is repeatable. HashMap the underlying data structure is a hash table. Thread insecure, high efficiency hash table relies on two methods: Hashcode () and Equals () execution order: first determine whether the hashcode () value is the same Yes: Continue with equals () to see that its return value is true: The description element is duplicated, not added is false: added directly to the set No: Add directly to the collection final: Automatically generate Hashcode () and Equals () to Linkedhashm The AP underlying data structure consists of a linked list and a hash table. The chain list guarantees an orderly element. The element is guaranteed to be unique by a hash table. Hashtable the underlying data structure is a hash table. Thread-safe, inefficient hash table relies on two methods: Hashcode () and Equals () execution order: first determine whether the hashcode () value is the same Yes: Continue with equals () to see that its return value is true: The description element is duplicated, not added is false: Add directly to the collection no: Add directly to the collection final: auto-generate Hashcode () and Equals () to TreeMap the underlying data structure is a red-black tree. (is a self-balancing two-fork tree) How to guarantee the uniqueness of the element? Determines how the elements are ordered, based on whether the return value of the comparison is? Natural ordering in two ways (the element is comparative) enables the class to which the element belongs implements the comparable interface comparer sort (collection With comparison) let the collection receive a comparator implementation class object 2. About whether the collection selection principle is a key-value object form: Yes: the MAP key needs to be sorted: Yes: TreeMap No: HashMap do not know, use HASHMAP. No: The Collection element is unique: Yes: whether the Set element needs to be sorted: Yes: TreeSet No: HashSet do not know, use HashSet No: List to Safe: Yes: Vector No: ArrayList or LinkedList and more: LinkedList query MORE: ArrayList do not know, use ArrayList do not know, use ArrayList 3: Common methods of collection and Traverse mode Collection:add () Remove () contains () iterator () size () Traversal: For |--list get () Traversal: for |--set map:put () Remove () ContainsKey (), Containsvalue () KeySet () get () Value () EntrySet () size () Traversal: Find values based on key values for keys and values based on key value
Java source parsing container class list, Set, Map