Java record-42-Java ArrayList

Source: Internet
Author: User

Java record-42-Java ArrayList
Public class ArrayList <E> extends actlist <E> I mplements List <E>, RandomAccess, Cloneable, SerializableArrayList is an array with variable size that implements the List interface. All optional list operations are implemented, and all elements including null are allowed. In addition to the List interface, this class also provides some methods to operate on the size of the array. The size of the array here refers to the size of the internal storage list. (This is basically equivalent to the Vector class, except that this class is not synchronized .) These operations, such as size, isEmpty, get, set, iterator, and listIterator, run at a fixed time (run in constant time ). The add operation runs at a scheduled time, that is, it takes O (n) Time to add n elements. All other operations are run in linear time (in general ). Compared with the constant factor used for the implementation of the sort list, the constant factor for this implementation is low. Each ArrayList instance has a capacity. This capacity refers to the size of the array used to store list elements. It is always equal to at least the size of the list. As elements are added to the ArrayList, their capacity increases automatically. The details of the growth policy are not specified, because it is not just as simple as adding an element to allocate a fixed time overhead. The ArrayList can only store objects, and the value is a runtime judgment rather than a compilation judgment. That is, only the runtime can know whether the object to be obtained is consistent with the actually retrieved object, whether an exception is thrown. 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 in the specified collection into the list starting from the specified position. Boolean remove (Object o) removes the specified Element (if any) that appears for the first time in this list ). Protected void removeRange (int fromIndex, int toIndex) removes all elements in the list between fromIndex (included) and toIndex (excluded.

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.