Correct use of ArrayList and linkedlist-performance improvement

Source: Internet
Author: User

USING ArrayList and LinkedList

ArrayList and LinkedList are two collections classes the for used storing of object lists. For example, your could have an ArrayList of Strings, or a linkedlist of integers. This tip compares the performance of ArrayList and LinkedList, and offers some suggestions about which of these classes are The right choice in a given situation.

The the ' The ' is ' is ' backed by a primitive Object array. Because of that, a ArrayList are much faster than a linkedlist for random access, which is, when accessing arbitrary list E Lements using the Get method. Note This get method is implemented for linkedlists, but it requires a sequential scan from the front or back of the L Ist. This scan is very slow. For a linkedlist, there ' s no fast way to access the nth element of the list.

Consider the following example. Suppose you have a large list of sorted elements, either a ArrayList. Suppose too that's on the list of binary search. The standard binary search algorithm starts by checking the search key against the "the" in the middle of the list. If the middle value is too high, then the upper half of the the the list is eliminated. However, if the middle value is too low, then the lower half of the the ' list is ignored. This process continues until the ' key is ' found in the list, or until the lower bound of the search becomes greater the Upper bound.

Here's a program which does a binary search on all of the elements in a ArrayList or a Lin

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.