IT. Expert System.

Android Reference

ArrayList


java.util

Class ArrayList<E>

  • Type Parameters:
    E - The element type of this list.
    All Implemented Interfaces:
    Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess


    public class ArrayList<E>
    extends AbstractList<E>
    implements Cloneable, Serializable, RandomAccess
    ArrayList is an implementation of List, backed by an array. All optional operations including adding, removing, and replacing elements are supported.

    All elements are permitted, including null.

    This class is a good choice as your default List implementation. Vector synchronizes all operations, but not necessarily in a way that's meaningful to your application: synchronizing each call to get, for example, is not equivalent to synchronizing the list and iterating over it (which is probably what you intended). CopyOnWriteArrayList is intended for the special case of very high concurrency, frequent traversals, and very rare mutations.

    Since:
    1.2
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors
      Constructor and Description
      ArrayList()
      Constructs a new ArrayList instance with zero initial capacity.
      ArrayList(Collection<? extends E> collection)
      Constructs a new instance of ArrayList containing the elements of the specified collection.
      ArrayList(int capacity)
      Constructs a new instance of ArrayList with the specified initial capacity.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      boolean add(E object)
      Adds the specified object at the end of this ArrayList.
      void add(int index, E object)
      Inserts the specified object into this ArrayList at the specified location.
      boolean addAll(Collection<? extends E> collection)
      Adds the objects in the specified collection to this ArrayList.
      boolean addAll(int index, Collection<? extends E> collection)
      Inserts the objects in the specified collection at the specified location in this List.
      void clear()
      Removes all elements from this ArrayList, leaving it empty.
      Object clone()
      Returns a new ArrayList with the same elements, the same size and the same capacity as this ArrayList.
      boolean contains(Object object)
      Searches this ArrayList for the specified object.
      void ensureCapacity(int minimumCapacity)
      Ensures that after this operation the ArrayList can hold the specified number of elements without further growing.
      boolean equals(Object o)
      Compares the specified object to this list and return true if they are equal.
      E get(int index)
      Returns the element at the specified location in this list.
      int hashCode()
      Returns the hash code of this list.
      int indexOf(Object object)
      Searches this list for the specified object and returns the index of the first occurrence.
      boolean isEmpty()
      Returns if this Collection contains no elements.
      Iterator<E> iterator()
      Returns an iterator on the elements of this list.
      int lastIndexOf(Object object)
      Searches this list for the specified object and returns the index of the last occurrence.
      E remove(int index)
      Removes the object at the specified location from this list.
      boolean remove(Object object)
      Removes one instance of the specified object from this Collection if one is contained (optional).
      protected void removeRange(int fromIndex, int toIndex)
      Removes the objects in the specified range from the start to the end index minus one.
      E set(int index, E object)
      Replaces the element at the specified location in this ArrayList with the specified object.
      int size()
      Returns the number of elements in this ArrayList.
      Object[] toArray()
      Returns a new array containing all elements contained in this ArrayList.
      <T> T[] toArray(T[] contents)
      Returns an array containing all elements contained in this ArrayList.
      void trimToSize()
      Sets the capacity of this ArrayList to be the same as the current size.
    • Constructor Detail

      • ArrayList

        public ArrayList(int capacity)
        Constructs a new instance of ArrayList with the specified initial capacity.
        Parameters:
        capacity - the initial capacity of this ArrayList.
      • ArrayList

        public ArrayList()
        Constructs a new ArrayList instance with zero initial capacity.
      • ArrayList

        public ArrayList(Collection<? extends E> collection)
        Constructs a new instance of ArrayList containing the elements of the specified collection.
        Parameters:
        collection - the collection of elements to add.
    • Method Detail

      • add

        public boolean add(E object)
        Adds the specified object at the end of this ArrayList.
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface List<E>
        Overrides:
        add in class AbstractList<E>
        Parameters:
        object - the object to add.
        Returns:
        always true
      • add

        public void add(int index,
               E object)
        Inserts the specified object into this ArrayList at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this ArrayList, the object is added at the end.
        Specified by:
        add in interface List<E>
        Overrides:
        add in class AbstractList<E>
        Parameters:
        index - the index at which to insert the object.
        object - the object to add.
        Throws:
        IndexOutOfBoundsException - when location < 0 || location > size()
      • addAll

        public boolean addAll(Collection<? extends E> collection)
        Adds the objects in the specified collection to this ArrayList.
        Specified by:
        addAll in interface Collection<E>
        Specified by:
        addAll in interface List<E>
        Overrides:
        addAll in class AbstractCollection<E>
        Parameters:
        collection - the collection of objects.
        Returns:
        true if this ArrayList is modified, false otherwise.
      • addAll

        public boolean addAll(int index,
                     Collection<? extends E> collection)
        Inserts the objects in the specified collection at the specified location in this List. The objects are added in the order they are returned from the collection's iterator.
        Specified by:
        addAll in interface List<E>
        Overrides:
        addAll in class AbstractList<E>
        Parameters:
        index - the index at which to insert.
        collection - the collection of objects.
        Returns:
        true if this ArrayList is modified, false otherwise.
        Throws:
        IndexOutOfBoundsException - when location < 0 || location > size()
      • clone

        public Object clone()
        Returns a new ArrayList with the same elements, the same size and the same capacity as this ArrayList.
        Overrides:
        clone in class Object
        Returns:
        a shallow copy of this ArrayList
        See Also:
        Cloneable
      • ensureCapacity

        public void ensureCapacity(int minimumCapacity)
        Ensures that after this operation the ArrayList can hold the specified number of elements without further growing.
        Parameters:
        minimumCapacity - the minimum capacity asked for.
      • get

        public E get(int index)
        Description copied from class: AbstractList
        Returns the element at the specified location in this list.
        Specified by:
        get in interface List<E>
        Specified by:
        get in class AbstractList<E>
        Parameters:
        index - the index of the element to return.
        Returns:
        the element at the specified index.
      • size

        public int size()
        Returns the number of elements in this ArrayList.
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface List<E>
        Specified by:
        size in class AbstractCollection<E>
        Returns:
        the number of elements in this ArrayList.
      • contains

        public boolean contains(Object object)
        Searches this ArrayList for the specified object.
        Specified by:
        contains in interface Collection<E>
        Specified by:
        contains in interface List<E>
        Overrides:
        contains in class AbstractCollection<E>
        Parameters:
        object - the object to search for.
        Returns:
        true if object is an element of this ArrayList, false otherwise
      • indexOf

        public int indexOf(Object object)
        Description copied from class: AbstractList
        Searches this list for the specified object and returns the index of the first occurrence.
        Specified by:
        indexOf in interface List<E>
        Overrides:
        indexOf in class AbstractList<E>
        Parameters:
        object - the object to search for.
        Returns:
        the index of the first occurrence of the object, or -1 if it was not found.
      • lastIndexOf

        public int lastIndexOf(Object object)
        Description copied from class: AbstractList
        Searches this list for the specified object and returns the index of the last occurrence.
        Specified by:
        lastIndexOf in interface List<E>
        Overrides:
        lastIndexOf in class AbstractList<E>
        Parameters:
        object - the object to search for.
        Returns:
        the index of the last occurrence of the object, or -1 if the object was not found.
      • remove

        public E remove(int index)
        Removes the object at the specified location from this list.
        Specified by:
        remove in interface List<E>
        Overrides:
        remove in class AbstractList<E>
        Parameters:
        index - the index of the object to remove.
        Returns:
        the removed object.
        Throws:
        IndexOutOfBoundsException - when location < 0 || location >= size()
      • remove

        public boolean remove(Object object)
        Description copied from class: AbstractCollection
        Removes one instance of the specified object from this Collection if one is contained (optional). This implementation iterates over this Collection and tests for each element e returned by the iterator, whether e is equal to the given object. If object != null then this test is performed using object.equals(e), otherwise using object == null. If an element equal to the given object is found, then the remove method is called on the iterator and true is returned, false otherwise. If the iterator does not support removing elements, an UnsupportedOperationException is thrown.
        Specified by:
        remove in interface Collection<E>
        Specified by:
        remove in interface List<E>
        Overrides:
        remove in class AbstractCollection<E>
        Parameters:
        object - the object to remove.
        Returns:
        true if this Collection is modified, false otherwise.
      • removeRange

        protected void removeRange(int fromIndex,
                       int toIndex)
        Description copied from class: AbstractList
        Removes the objects in the specified range from the start to the end index minus one.
        Overrides:
        removeRange in class AbstractList<E>
        Parameters:
        fromIndex - the index at which to start removing.
        toIndex - the index after the last element to remove.
      • set

        public E set(int index,
            E object)
        Replaces the element at the specified location in this ArrayList with the specified object.
        Specified by:
        set in interface List<E>
        Overrides:
        set in class AbstractList<E>
        Parameters:
        index - the index at which to put the specified object.
        object - the object to add.
        Returns:
        the previous element at the index.
        Throws:
        IndexOutOfBoundsException - when location < 0 || location >= size()
      • toArray

        public <T> T[] toArray(T[] contents)
        Returns an array containing all elements contained in this ArrayList. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this ArrayList, the array element following the collection elements is set to null.
        Specified by:
        toArray in interface Collection<E>
        Specified by:
        toArray in interface List<E>
        Overrides:
        toArray in class AbstractCollection<E>
        Parameters:
        contents - the array.
        Returns:
        an array of the elements from this ArrayList.
        Throws:
        ArrayStoreException - when the type of an element in this ArrayList cannot be stored in the type of the specified array.
      • trimToSize

        public void trimToSize()
        Sets the capacity of this ArrayList to be the same as the current size.
        See Also:
        size
      • equals

        public boolean equals(Object o)
        Description copied from class: AbstractList
        Compares the specified object to this list and return true if they are equal. Two lists are equal when they both contain the same objects in the same order.
        Specified by:
        equals in interface Collection<E>
        Specified by:
        equals in interface List<E>
        Overrides:
        equals in class AbstractList<E>
        Parameters:
        o - the object to compare to this object.
        Returns:
        true if the specified object is equal to this list, false otherwise.
        See Also:
        AbstractList.hashCode()


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 293 / . Delta: 0.03397 с