Java source parsing container class list, Set, Map

Source: Internet
Author: User
Tags comparable

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

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.