Java Set Create toSet(Set set)

Here you can find the source of toSet(Set set)

Description

to Set

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> Set<T> toSet(Set<?> set) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> Set<T> toSet(Set<?> set) {
        Set<T> setOfType = new HashSet<T>(set.size());
        Iterator<?> iter = set.iterator();
        while (iter.hasNext()) {
            T element = (T) iter.next();
            setOfType.add(element);/* www.  j a v a  2  s .com*/
        }
        return setOfType;
    }
}

Related

  1. asSet(T... values)
  2. asSet(T... values)
  3. toSet(Iterable things)
  4. toSet(Iterable items)
  5. toSet(Object[] someElements)
  6. toSet(String[] aStringArray)
  7. toSet(T... objects)
  8. unmodifiableSet(final Set s, final boolean newSet, final boolean emptyAsNull)