Java Collection Class Learning notes (various linear table performance analysis)

Source: Internet
Author: User

ArrayList and LinkedList are two typical implementations of linear tables: array-based linear tables and chain-based linear tables.

The queue represents queues, and deque represents a double-ended queue.

In general, because the array holds all the array elements in a contiguous memory area, the array has the best performance at random access;

The set of the internal list as the bottom implementation of the implementation of the INSERT, delete operations have good performance.

Overall, ArrayList performance is better than LinkedList performance, so ArrayList should be considered most of the time.

Here are some suggestions for using the list collection:

  1. If you need to traverse the list collection element, for ArrayList, vector collections, you should use the random access method (get) to traverse the performance better, and for the LinkedList collection, you should use Iterators (Iterator) to iterate through the collection elements.
  2. If you want to change a list collection that contains large amounts of data frequently, you should use the LinkedList collection. Because using ArrayList, vector collections may require frequent reallocation of memory.
  3. If you have multiple threads that need to access the elements in the list collection at the same time, consider wrapping the collection as a thread-safe collection using collections.

Java Collection Class Learning notes (various linear table performance analysis)

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.