Java Records -42-java ArrayList

Source: Internet
Author: User

public class Arraylist<e> extends Abstractlist<e>i mplements list<e>, Randomaccess, Cloneable, Serializable

ArrayListis a realization of theListThe size of the interface is variableArray. Implements all the optionalListoperation, and includes the AllowNULLall elements are included. In addition to implementingListinterface, this class also provides methods to manipulateArraythe size, here's theArraysize refers to the interior used to storeListthe size. (This class is roughly equivalent toVectorclass, except this class is not synchronized. )

these operations such as size,isEmpty,get,set, Both iterator and listiterator are run at a fixed time ( run in constant time). Add operations are run at a fixed time that is apportioned, that is, adding N elements require a O (n) time. All other operations run in linear time (broadly speaking). This implementation has a low constant factor compared to the constant factor used for LinkedList implementations.

Each ArrayList instance has a capacity. This capacity refers to the size of the array used to store the list elements. It is always at least equal to the size of the list. As You add elements to the ArrayList, their capacity increases automatically. The details of the growth strategy are not specified, as it is not just the addition of elements that can be as simple as allocating fixed-time overhead.


ArrayList can only hold objects, and the value is run-time judgment rather than compile-time judgment, that is, only at run time to know that the object you want to get and the actual object is consistent, whether throws an exception.


Several special methods:

void Add (int index, E Element)

Inserts the specified element into the specified position in this list.

Boolean addall (int index, COLLECTION<? extends e> c)

Inserts all elements from the specified collection into this list, starting at the specified location.

Boolean remove (Object o)

Removes the specified element (if any) that first appears in this list.

protected void RemoveRange (int fromIndex, int toindex)

Removes all elements in the list between FromIndex(inclusive) and toindex(not included).


Java Records -42-java ArrayList

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.