public final class Lists2 extends Object
"Immutable List Static Factory Methods" in the List
interface.
The Lists.of() static factory methods provide a
convenient way to create immutable lists. The List instances created
by these methods have the following characteristics:
UnsupportedOperationException to be thrown.
However, if the contained elements are themselves mutable,
this may cause the List's contents to appear to change.
null elements. Attempts to create them with
null elements result in NullPointerException.
==), identity hash code, and synchronization) are unreliable and
should be avoided.
| Modifier and Type | Method and Description |
|---|---|
static <E> List<E> |
of()
Returns an immutable list containing zero elements.
|
static <E> List<E> |
of(E... elements)
Returns an immutable list containing an arbitrary number of elements.
|
static <E> List<E> |
of(E e1)
Returns an immutable list containing one element.
|
static <E> List<E> |
of(E e1,
E e2)
Returns an immutable list containing two elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3)
Returns an immutable list containing three elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4)
Returns an immutable list containing four elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5)
Returns an immutable list containing five elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6)
Returns an immutable list containing six elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7)
Returns an immutable list containing seven elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7,
E e8)
Returns an immutable list containing eight elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7,
E e8,
E e9)
Returns an immutable list containing nine elements.
|
static <E> List<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7,
E e8,
E e9,
E e10)
Returns an immutable list containing ten elements.
|
public static <E> List<E> of()
E - the List's element typeListpublic static <E> List<E> of(E e1)
E - the List's element typee1 - the single elementList containing the specified elementNullPointerException - if the element is nullpublic static <E> List<E> of(E e1, E e2)
E - the List's element typee1 - the first elemente2 - the second elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4, E e5)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elemente7 - the seventh elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elemente7 - the seventh elemente8 - the eighth elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elemente7 - the seventh elemente8 - the eighth elemente9 - the ninth elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
E - the List's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elemente7 - the seventh elemente8 - the eighth elemente9 - the ninth elemente10 - the tenth elementList containing the specified elementsNullPointerException - if an element is nullpublic static <E> List<E> of(E... elements)
API Note:
This method also accepts a single array as an argument. The element type of
the resulting list will be the component type of the array, and the size of
the list will be equal to the length of the array. To create a list with
a single element that is an array, do the following:
String[] array = ... ;
List<String[]> list = Lists.<String[]>of(array);
This will cause the Lists.of(E) method
to be invoked instead.E - the List's element typeelements - the elements to be contained in the listList containing the specified elementsNullPointerException - if an element is null or if the array is nullCopyright © 2016. All rights reserved.