Java BASICS (16) Set (3) and java basics set

Source: Internet
Author: User
Tags comparable

Java BASICS (16) Set (3) and java basics set

Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!

It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!

Also very welcome to my blog to watch blog address: http://www.cnblogs.com/duscl/

 

/* 1: logon registration case (understanding) 2: Set (understanding) (1) unordered Set characteristics, unique (2) HashSet Set (master): the underlying data structure is a hash table (an array whose elements are linked lists) B: The underlying hash table relies on two methods: hashCode () and equals () execution order: first, compare whether the hash value is the same: continue to execute the equals () method, return true: the element is repeated, do not add, return false: directly add the element to the set is different: add the element directly to the set C: how to ensure the uniqueness of the element? D, guaranteed by hashCode () and equals (): during development, the code is very simple and can be automatically generated. E: HashSet stores strings and traverses F: HashSet stores custom objects and traverses (the object's member variable values are the same element) (3) TreeSet set: the underlying data structure is a red/black tree (a self-balanced binary tree) B: ensures that the elements are sorted in a: natural order (the elements are Comparable) so that the class to which the elements belong implements the Comparable interface B: the Comparator sorting (set comparison) allows the set constructor to receive Comparator implementation Class Object C: Read the code we 've Mentioned Again (4) case:: obtain a random number without repetition. B: input data on the keyboard. Output data from the top to the bottom according to the total score. 3: Collection set Summary (master) Collection | -- List order, repeatable | -- the underlying data structure of ArrayList is an array, which is fast in query and slow in addition or deletion. Low thread security and high efficiency | -- the underlying data structure of the Vector is an array, which provides fast query and slow addition and deletion. Thread security and low efficiency | -- the underlying data structure of the consumer list is a linked list, which is slow in query and fast in addition and deletion. Threads are not secure and efficient. | -- Set unordered and unique | the underlying data structure of -- HashSet is a hash table. How can we ensure the uniqueness of elements? Two methods are required: hashCode () and equals () the two methods are automatically generated during development. | -- the underlying data structure of javashashset is the linked list and hash table. The linked list ensures that elements are ordered. The hash table ensures that elements are unique. | -- the underlying data structure of TreeSet is a red/black tree. How can we ensure the sorting of elements? How does the sort by natural sorting comparator ensure the uniqueness of elements? Determine 4 based on whether the returned value is 0: Who should we use for the Collection set? (MASTER) Is it unique? Yes: Set sorting? Yes: TreeSet No: HashSet. If you know the Set but do not know which Set it is, use HashSet. No: Is List secure? Yes: Vector No: ArrayList or ArrayList many queries: ArrayList addition, deletion, and more: ArrayList. If you know it is a List but you do not know which List it is, ArrayList is used. If you know the Collection, but you do not know who to use, use ArrayList. If you know that a set is used, ArrayList is used. 5: Common Data Structures in the collection (master) ArrayXxx: the underlying data structure is an array, fast query, and slow addition/deletion. XXX: the underlying data structure is a linked list, slow query, and fast addition/deletion. HashXxx: the underlying data structure is a hash table. Two methods are required: hashCode () and equals () TreeXxx: the underlying data structure is a binary tree. Two sorting methods: Natural sorting and comparator sorting *\

 

Related Article

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.