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

SettoSet(Object[] someElements)
to Set
Set asSet = new HashSet(someElements.length);
for (int i = 0; i < someElements.length; i++)
    asSet.add(someElements[i]);
return asSet;
SettoSet(Set set)
to Set
Set<T> setOfType = new HashSet<T>(set.size());
Iterator<?> iter = set.iterator();
while (iter.hasNext()) {
    T element = (T) iter.next();
    setOfType.add(element);
return setOfType;
SettoSet(String[] aStringArray)
Converts a string array to a set of strings.
Set<String> set = new LinkedHashSet<>();
if (aStringArray != null) {
    Collections.addAll(set, aStringArray);
return set;
SettoSet(T... objects)
Create an Object Set from the supplied objects.
Set<T> theSet = new HashSet<T>();
addToCollection(theSet, objects);
return theSet;
SetunmodifiableSet(final Set s, final boolean newSet, final boolean emptyAsNull)
unmodifiable Set
if (s == null) {
    return null;
if (emptyAsNull && s.isEmpty()) {
    return null;
return Collections.unmodifiableSet(newSet ? new HashSet<>(s) : s);