public class Sets
extends java.lang.Object
Set instances easily and
other static methods for working with Sets.
Note: This was copied from the com.google.android.collect.Lists class| Constructor and Description |
|---|
Sets() |
| Modifier and Type | Method and Description |
|---|---|
static <K> java.util.HashSet<K> |
newHashSet()
Creates an empty
HashSet instance. |
static <E> java.util.HashSet<E> |
newHashSet(E... elements)
Creates a
HashSet instance containing the given elements. |
static <E> java.util.SortedSet<E> |
newSortedSet(E... elements)
Creates a
SortedSet instance containing the given elements. |
public static <K> java.util.HashSet<K> newHashSet()
HashSet instance.
Note: if E is an Enum type, use EnumSet.noneOf(java.lang.Class<E>) instead.
Note: if you only need an immutable empty Set,
use Collections.emptySet() instead.
HashSetpublic static <E> java.util.HashSet<E> newHashSet(E... elements)
HashSet instance containing the given elements.
Note: due to a bug in javac 1.5.0_06, we cannot support the following:
Set<Base> set = Sets.newHashSet(sub1, sub2);
where sub1 and sub2 are references to subtypes of Base, not of Base itself. To get around this, you must use:
Set<Base> set = Sets.<Base>newHashSet(sub1, sub2);
elements - the elements that the set should containHashSet containing those elements (minus
duplicates)public static <E> java.util.SortedSet<E> newSortedSet(E... elements)
SortedSet instance containing the given elements.elements - the elements that the set should containSortedSet containing those elements (minus
duplicates)