public final class Sets2 extends Object
"Immutable Set Static Factory Methods" in the Set
interface.
The Sets.of() static factory methods provide a
convenient way to create immutable sets. The Set 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
Set to behave inconsistently or its contents to appear to change.
null elements. Attempts to create them with
null elements result in NullPointerException.
IllegalArgumentException.
==), identity hash code, and synchronization) are unreliable and
should be avoided.
| Modifier and Type | Method and Description |
|---|---|
static <E> Set<E> |
of()
Returns an immutable set containing zero elements.
|
static <E> Set<E> |
of(E... elements)
Returns an immutable set containing an arbitrary number of elements.
|
static <E> Set<E> |
of(E e1)
Returns an immutable set containing one element.
|
static <E> Set<E> |
of(E e1,
E e2)
Returns an immutable set containing two elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3)
Returns an immutable set containing three elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3,
E e4)
Returns an immutable set containing four elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5)
Returns an immutable set containing five elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6)
Returns an immutable set containing six elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7)
Returns an immutable set containing seven elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7,
E e8)
Returns an immutable set containing eight elements.
|
static <E> Set<E> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E e7,
E e8,
E e9)
Returns an immutable set containing nine elements.
|
static <E> Set<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 set containing ten elements.
|
public static <E> Set<E> of()
E - the Set's element typeSetpublic static <E> Set<E> of(E e1)
E - the Set's element typee1 - the single elementSet containing the specified elementNullPointerException - if the element is nullpublic static <E> Set<E> of(E e1, E e2)
E - the Set's element typee1 - the first elemente2 - the second elementSet containing the specified elementsIllegalArgumentException - if the elements are duplicatesNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3)
E - the Set's element typee1 - the first elemente2 - the second elemente3 - the third elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4)
E - the Set's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5)
E - the Set's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6)
E - the Set's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
E - the Set's element typee1 - the first elemente2 - the second elemente3 - the third elemente4 - the fourth elemente5 - the fifth elemente6 - the sixth elemente7 - the seventh elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
E - the Set'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 elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
E - the Set'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 elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
E - the Set'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 elementSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is nullpublic static <E> Set<E> of(E... elements)
API Note:
This method also accepts a single array as an argument. The element type of
the resulting set will be the component type of the array, and the size of
the set will be equal to the length of the array. To create a set with
a single element that is an array, do the following:
String[] array = ... ;
Set<String[]> list = Sets.<String[]>of(array);
This will cause the Set.of(E) method
to be invoked instead.E - the Set's element typeelements - the elements to be contained in the setSet containing the specified elementsIllegalArgumentException - if there are any duplicate elementsNullPointerException - if an element is null or if the array is nullCopyright © 2016. All rights reserved.