Java Array to Set toSet(final TYPE[] array)

Here you can find the source of toSet(final TYPE[] array)

Description

to Set

License

Open Source License

Declaration

public static <TYPE> Set<TYPE> toSet(final TYPE[] array) 

Method Source Code


//package com.java2s;

import java.util.Collections;
import java.util.HashSet;

import java.util.Set;

public class Main {
    public static <TYPE> Set<TYPE> toSet(final TYPE[] array) {
        if (array == null) {
            return Collections.emptySet();
        }//from   www  . j  ava 2s . co  m
        final Set<TYPE> result = new HashSet<TYPE>();
        for (int i = 0; i < array.length; i++) {
            result.add(array[i]);
        }
        return result;
    }
}

Related

  1. arrayToSet(final T[] array)
  2. arrayToSet(Object[] in)
  3. toSet(T[] array)
  4. translateToSet(T[] array)