Class ReferenceArrayList<K>

All Implemented Interfaces:
ObjectIterable<K>, ReferenceCollection<K>, ReferenceList<K>, Stack<K>, Serializable, Cloneable, Iterable<K>, Collection<K>, List<K>, RandomAccess

public class ReferenceArrayList<K>
extends AbstractReferenceList<K>
implements RandomAccess, Cloneable, Serializable
A type-specific array-based list; provides some additional methods that use polymorphism to avoid (un)boxing.

This class implements a lightweight, fast, open, optimized, reuse-oriented version of array-based lists. Instances of this class represent a list with an array that is enlarged as needed when new entries are created (by doubling the current length), but is never made smaller (even on a clear()). A family of trimming methods lets you control the size of the backing array; this is particularly useful if you reuse instances of this class. Range checks are equivalent to those of java.util's classes, but they are delayed as much as possible.

The backing array is exposed by the elements() method. If an instance of this class was created by wrapping, backing-array reallocations will be performed using reflection, so that elements() can return an array of the same type of the original array: the comments about efficiency made in ObjectArrays apply here. Moreover, you must take into consideration that assignment to an array not of type Object[] is slower due to type checking.

This class implements the bulk methods removeElements(), addElements() and getElements() using high-performance system calls (e.g., System.arraycopy() instead of expensive loops.

See Also:
ArrayList, Serialized Form
  • Field Details

  • Constructor Details

    • ReferenceArrayList

      public ReferenceArrayList​(int capacity)
      Creates a new array list with given capacity.
      Parameters:
      capacity - the initial capacity of the array list (may be 0).
    • ReferenceArrayList

      public ReferenceArrayList()
      Creates a new array list with DEFAULT_INITIAL_CAPACITY capacity.
    • ReferenceArrayList

      public ReferenceArrayList​(Collection<? extends K> c)
      Creates a new array list and fills it with a given collection.
      Parameters:
      c - a collection that will be used to fill the array list.
    • ReferenceArrayList

      public ReferenceArrayList​(ReferenceCollection<? extends K> c)
      Creates a new array list and fills it with a given type-specific collection.
      Parameters:
      c - a type-specific collection that will be used to fill the array list.
    • ReferenceArrayList

      public ReferenceArrayList​(ReferenceList<? extends K> l)
      Creates a new array list and fills it with a given type-specific list.
      Parameters:
      l - a type-specific list that will be used to fill the array list.
    • ReferenceArrayList

      public ReferenceArrayList​(K[] a)
      Creates a new array list and fills it with the elements of a given array.
      Parameters:
      a - an array whose elements will be used to fill the array list.
    • ReferenceArrayList

      public ReferenceArrayList​(K[] a, int offset, int length)
      Creates a new array list and fills it with the elements of a given array.
      Parameters:
      a - an array whose elements will be used to fill the array list.
      offset - the first element to use.
      length - the number of elements to use.
    • ReferenceArrayList

      public ReferenceArrayList​(Iterator<? extends K> i)
      Creates a new array list and fills it with the elements returned by an iterator..
      Parameters:
      i - an iterator whose returned elements will fill the array list.
    • ReferenceArrayList

      public ReferenceArrayList​(ObjectIterator<? extends K> i)
      Creates a new array list and fills it with the elements returned by a type-specific iterator..
      Parameters:
      i - a type-specific iterator whose returned elements will fill the array list.
  • Method Details