Class UnmodifiableArrayList.SubList<E>

Type Parameters:
E - the type of elements in the list.
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>, RandomAccess, SequencedCollection<E>, CheckedContainer<E>
Enclosing class:
UnmodifiableArrayList<E>

private static final class UnmodifiableArrayList.SubList<E> extends UnmodifiableArrayList<E>
A view over a portion of UnmodifiableArrayList.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • lower

      private final int lower
      Index of the first element and size of this list.
    • size

      private final int size
      Index of the first element and size of this list.
  • Constructor Details

    • SubList

      SubList(E[] array, int lower, int size)
      Creates a new sublist.

      WARNING! Type safety hole

      Callers must ensure that the type of array elements in exactly E, not a subtype of E. See UnmodifiableArrayList class javadoc for more information.
  • Method Details

    • lower

      int lower()
      Returns the index of the first element.
      Overrides:
      lower in class UnmodifiableArrayList<E>
    • size

      public int size()
      Returns the size of this list.
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
      Overrides:
      size in class UnmodifiableArrayList<E>
      Returns:
      the size of this list.
    • get

      public E get(int index)
      Returns the element at the given index.
      Specified by:
      get in interface List<E>
      Overrides:
      get in class UnmodifiableArrayList<E>
      Parameters:
      index - the index of the element to get.
      Returns:
      the element at the given index.
    • toArray

      public E[] toArray()
      Returns a copy of the backing array section viewed by this sublist.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
      Overrides:
      toArray in class UnmodifiableArrayList<E>
      Returns:
      a copy of the wrapped array.