FileDocCategorySizeDatePackage
Sets.javaAPI DocAndroid 5.1 API3526Thu Mar 12 22:22:10 GMT 2015com.google.android.collect

Sets

public class Sets extends Object
Provides static methods for creating mutable {@code Set} instances easily and other static methods for working with Sets.

Fields Summary
Constructors Summary
Methods Summary
public static android.util.ArraySetnewArraySet()
Creates a {@code ArraySet} instance.

        return new ArraySet<E>();
    
public static android.util.ArraySetnewArraySet(E elements)
Creates a {@code ArraySet} instance containing the given elements.

        int capacity = elements.length * 4 / 3 + 1;
        ArraySet<E> set = new ArraySet<E>(capacity);
        Collections.addAll(set, elements);
        return set;
    
public static java.util.HashSetnewHashSet()
Creates an empty {@code HashSet} instance.

Note: if {@code E} is an {@link Enum} type, use {@link EnumSet#noneOf} instead.

Note: if you only need an immutable empty Set, use {@link Collections#emptySet} instead.

return
a newly-created, initially-empty {@code HashSet}

        return new HashSet<K>();
    
public static java.util.HashSetnewHashSet(E elements)
Creates a {@code HashSet} instance containing the given elements.

Note: due to a bug in javac 1.5.0_06, we cannot support the following:

{@code Set set = Sets.newHashSet(sub1, sub2);}

where {@code sub1} and {@code sub2} are references to subtypes of {@code Base}, not of {@code Base} itself. To get around this, you must use:

{@code Set set = Sets.newHashSet(sub1, sub2);}

param
elements the elements that the set should contain
return
a newly-created {@code HashSet} containing those elements (minus duplicates)

        int capacity = elements.length * 4 / 3 + 1;
        HashSet<E> set = new HashSet<E>(capacity);
        Collections.addAll(set, elements);
        return set;
    
public static java.util.SortedSetnewSortedSet()
Creates an empty {@code SortedSet} instance.

return
a newly-created, initially-empty {@code SortedSet}.

        return new TreeSet<E>();
    
public static java.util.SortedSetnewSortedSet(E elements)
Creates a {@code SortedSet} instance containing the given elements.

param
elements the elements that the set should contain
return
a newly-created {@code SortedSet} containing those elements (minus duplicates)

        SortedSet<E> set = new TreeSet<E>();
        Collections.addAll(set, elements);
        return set;