Summary of features and data structures of the Java 19-1 Collection

Source: Internet
Author: User
Tags comparable

1 1. Collection 2     Collection (Single-column collection)3       List (ordered, repeatable)4ArrayList5 The underlying data structure is an array, query fast, and delete slowly6 thread insecure, high efficiency7        Vector8 The underlying data structure is an array, query fast, and delete slowly9 thread-safe, low-efficiencyTen       LinkedList One The underlying data structure is linked list, query slow, delete quickly A thread insecure, high efficiency -Set (unordered, unique) -        HashSet the the underlying data structure is a hash table.  - hash table relies on two methods: Hashcode () and Equals () - Execution Order: - first determine if the hashcode () value is the same + yes: Continue with equals () to see its return value - is true: The description element is duplicated, not added + is false: it is added directly to the collection A No: Add directly to the collection at Final: - automatically generate Hashcode () and Equals () -                      -       Linkedhashset - The underlying data structure consists of a linked list and a hash table.  - The chain list guarantees an orderly element.  in the element is guaranteed to be unique by a hash table.  -         TreeSet to the underlying data structure is a red-black tree. (is a self-balancing two-fork tree) +How to guarantee the uniqueness of elements? - Depends on whether the return value of the comparison is theHow to ensure the ordering of elements? * two different ways $ Natural Sorting (elements are comparative)Panax Notoginseng implementing the comparable interface for the class to which the element belongs - Comparator sorting (collection with comparison) the let the collection receive a comparator implementation class object +     Map (double-column collection) A the data structure of the A:map collection is only valid for the key, regardless of the value.  the 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 if the hashcode () value is the same the yes: Continue with equals () to see its return value - is true: The description element is duplicated, not addedWuyi is false: it is added directly to the collection the No: Add directly to the collection - Final: Wu automatically generate Hashcode () and Equals () -       Linkedhashmap About 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.  -       Hashtable - the underlying data structure is a hash table. Thread-safe, low-efficiency A hash table relies on two methods: Hashcode () and Equals () + Execution Order: the first determine if the hashcode () value is the same - yes: Continue with equals () to see its return value $ is true: The description element is duplicated, not added the is false: it is added directly to the collection the No: Add directly to the collection the Final: the automatically generate Hashcode () and Equals () -       TreeMap in the underlying data structure is a red-black tree. (is a self-balancing two-fork tree) theHow to guarantee the uniqueness of elements? the Depends on whether the return value of the comparison is AboutHow to ensure the ordering of elements? the two different ways the Natural Sorting (elements are comparative) the implementing the comparable interface for the class to which the element belongs + Comparator sorting (collection with comparison) - let the collection receive a comparator implementation class object the     Bayi 2: What kind of collection  do you use? the look at the demand.  the      -     is the form of a key-value object: -       Yes: Map the        whether the key needs to be sorted: the Yes: TreeMap the No: HashMap the don't know, just use HashMap.  -              the     No: Collection the         element is unique: the Yes: Set94 whether the element needs to be sorted: the Yes: TreeSet the No: HashSet the I don't know, just use HashSet.98                      About No: List -          is it safe to:101 is: Vector (in fact, now do not use it, after explaining the multi-threaded, and then review with whom)102 No: ArrayList or LinkedList103 more additions and deletions: LinkedList104 query MORE: ArrayList the I don't know, just use ArrayList.106 I don't know, just use ArrayList.107             108 3: Common methods of collection and Traverse mode 109     Collection: the Add ()111 Remove () the contains ()113 iterator () the size () the          the      Traversal: 117 Enhanced for118 iterators119              -|--List121 get ()122             123 Traversal:124 General for the|--Set126     127     Map: - put ()129 Remove () the ContainsKey (), Containsvalue ()131 KeySet () the get ()133 value ()134 EntrySet ()135 size ()136         137       Traversal:138 find values by key139 to find keys and values for an object based on key values $             141 at least to achieve:142 any set that you have explained, what you need to store, and what you can store. 143 and, you have to be able to traverse it. 144 1454:arraylist,linkedlist,hashset,hashmap (master) 146 store strings and custom object data and Traverse147     1485: Nested Traversal of a collection (understanding)

Summary of features and data structures of the Java 19-1 Collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.