Java Core Class Library-collection Framework-arraylist class

Source: Internet
Author: User

The ArrayList class is the one that replaces the vector class when the Java collection framework appears.

The underlying principle is an array-based algorithm, identical.

Difference:

Vector: All methods use the Synchronize modifier thread-safe but low performance for multithreaded environments.

ArrayList: All methods do not use the Synchronize modifier thread is unsafe but has high performance.

Do not use the vector class even after multithreading

because: List List = Collections.synchronizedlist (new ArrayList (...));

Common methods refer to vector classes

Read the source code found that the vector class and the ArrayList class difference is a bit large ( from the set to consider )

Sometimes a method needs to return a ArrayList object

But in this method, if none of the queries are returned to NULL, we return an empty collection object (no collection of elements)

Before Java7, even though an object was created with new ArrayList, one element was not stored, but the object array of length 10 was still initialized in the heap space, wasting heap space.

To optimize this design from JAVA7, new ArrayList actually creates an empty array that will be reinitialized when Add.

Java Core Class Library-collection Framework-arraylist class

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.