Class MinimalList


public final class MinimalList extends Object
MinimalList provides a set of static methods to dynamically choose the most efficient List implementation. The implementation of List is changed as needed. MinimalList is most suited for building list-based data structures that use less heap space than a pure ArrayList-based solution.

size=0: Collections.emptyList()
size=1: Collections.singletonList(java.lang.Object)
size=2: ArrayList

AO Industries, Inc.
  • Method Details

    • emptyList

      public static <E> List<E> emptyList()
      Gets the empty list representation.
    • add

      public static <E> List<E> add(List<E> list, E elem)
      Adds a new element to a list, returning the (possibly new) list.
    • get

      @Deprecated public static <E> E get(List<E> list, int index) throws IndexOutOfBoundsException
      Since empty lists are no longer represented by null, invoke List.get(int) directly now.
      Gets an element from a list.
    • copy

      public static <E> List<E> copy(List<E> list)
      Performs a shallow copy of a list. The list is assumed to have been created by MinimalList and to be used through MinimalList.
    • unmodifiable

      public static <E> List<E> unmodifiable(List<E> list)
      Gets an unmodifiable wrapper around this list. May or may not wrap this list itself.