Java Utililty Methods Set Create

List of utility methods to do Set Create

Description

The list of methods to do Set Create are organized into topic(s).

Method

SetasSet(T... elements)
as Set
Set<T> toReturn = new HashSet<>();
toReturn.addAll(Arrays.asList(elements));
return toReturn;
SetasSet(T... elements)
as Set
return asLinkedSet(elements);
SetasSet(T... elements)
Creates a java.util.Set with the given elements.
final Set<T> resultSet = new LinkedHashSet<T>();
addAll(resultSet, elements);
return resultSet;
SetasSet(T... items)
as Set
Set<T> set = new LinkedHashSet<T>();
Collections.addAll(set, items);
return set;
SetasSet(T... ts)
as Set
Set<T> set = new HashSet<>(getInitialCapacityFromExpectedSize(ts.length));
Collections.addAll(set, ts);
return set;
SetasSet(T... ts)
Returns an unmodifiable set containing the given elements.
if (ts == null) {
    return null;
} else if (ts.length == 0) {
    return Collections.emptySet();
} else {
    Set<T> set = new HashSet<T>(ts.length);
    Collections.addAll(set, ts);
    return Collections.unmodifiableSet(set);
...
SetasSet(T... values)
as Set
return new HashSet<>(asList(values));
SetasSet(T... values)
as Set
return new HashSet<>(Arrays.asList(values));
SettoSet(Iterable things)
to Set
if (things == null) {
    return new HashSet<T>(0);
if (things instanceof Set) {
    @SuppressWarnings("unchecked")
    Set<T> castThings = (Set<T>) things;
    return castThings;
Set<T> set = new LinkedHashSet<T>();
for (T thing : things) {
    set.add(thing);
return set;
SettoSet(Iterable items)
to Set
return toSet(items.iterator());