Chapter 7 Summary of common Java Collection classes and Chapter 7 java

Source: Internet
Author: User

Chapter 7 Summary of common Java Collection classes and Chapter 7 java

7.1. List (repeated elements are allowed)

  • ArrayList:
    • Underlying data structure: Object []
    • InGet, iterator, and set)ArrayList
    • Scalable, unlimited capacity
  • Shortlist
    • Underlying data structure: Annular two-way linked list
    • InAdd and remove)In the case of many operations, use the upload list
    • Linked List, unlimited capacity

Note:

1) add (E): inserts an element at the end of the array. ArrayList needs to consider the expansion problem. Once the expansion is completed, array copying is required, and the sort list is not required;

2) add (int index): insert an element in the middle of the array. In ArrayList, you must consider copying all the index and its array elements and moving them one by one.

7.2. Set (repeated elements are not allowed, so they can be used for deduplication)

  • HashSet:
    • Underlying data structure: HashMap
    • Can be seen as unlimited capacity
  • TreeSet:
    • Underlying data structure: TreeMap
    • Unlimited capacity

7.3 Map (key-value)

  • HashMap:
    • Underlying data structure: linked list Array
    • Scalable, and the maximum capacity is large, can be seen as unlimited capacity
  • TreeMap:
    • Underlying data structure: red/black tree
    • Sort by key(In use, either use TreeMap (Comparator) or let the key object implement Comparable)
    • Red/black tree with unlimited capacity

Note:

  • All the above threads are not secure
  • When the search and deletion are frequent and the number of elements is large (the number of elements is greater than 100), the Set and Map performance is better than the List (in the case of single thread)

The second conclusion above is in the book distributed Java basics: Applications and practices, Lin Hao obtained through a series of test results.

 

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.