Java Collection Convert toSet(Collection c)

Here you can find the source of toSet(Collection c)

Description

to Set

License

Open Source License

Parameter

Parameter Description
c a parameter

Return

a c if c is a or, otherwise, a containing the elements of c

Declaration

public static <T> Set<T> toSet(Collection<T> c) 

Method Source Code

//package com.java2s;

import java.util.*;

public class Main {
    /**/*from  ww  w  .  j a  v  a  2  s . co  m*/
     * @param c
     * @return a c if c is a {@link Set} or, otherwise, a {@link LinkedHashSet}
     * containing the elements of c
     */
    public static <T> Set<T> toSet(Collection<T> c) {
        return asSet(c);
    }

    /**
     * @param c
     * @return a c if c is a {@link Set} or, otherwise, a {@link LinkedHashSet}
     * containing the elements of c
     */
    public static <T> Set<T> asSet(Collection<T> c) {
        if (c instanceof Set) {
            return (Set<T>) c;
        }
        LinkedHashSet<T> set = new LinkedHashSet<T>(c);
        return set;
    }
}

Related

  1. toPrimitiveArray(final Collection values)
  2. toPrimitiveIntegerArray(Collection collection)
  3. toReadableString(Collection collection)
  4. toSeparatedString(Collection items, String separator)
  5. toSeperatedString(final Collection list)
  6. toSingleton(Collection l)
  7. toSQLIn(Collection values)
  8. toStringBuilder( Collection collection, String delimiter)
  9. toStringColl(Collection set)