将给定数组转换成Set。注意:相同hashCode的元素将只保留一个。Convert given array to a set.

@param array 源数组。source array.
@return 一个保留所有唯一元素的Set。a set have all unique element of array.
554073
public static <T> Set<T> toSet(final T[] array) {

    if (isNotEmpty(array)) {
      Set<T> set = new HashSet<T>(array.length);
      for (T element : array) {
        set.add(element);
      }
      return set;
    } else {
      return new HashSet<T>(0);
    }
  }
192975
public static List<Object> array2ObjectList(final Object array) {
        final int length = Array.getLength(array);
        final List<Object> list = new ArrayList<Object>(length);
        for (int i = 0; i < length; ++i) {
            list.add(Array.get(array, i));
        }
        return list;
    }
968816
public static <T> ArrayList<T> mergeLists(final T... array) {
        final ArrayList<T> retValue = new ArrayList<T>();
        Collections.addAll(retValue, array);
        return retValue;
    }
1245822
@SafeVarargs
	public static <E> HashSet<E> newHashSet(E... elements) {
		HashSet<E> set = new HashSet<E>();
		Collections.addAll(set, elements);
		return set;
	}
49477
public static IntStreamEx of(Integer[] array) {
        return seq(Arrays.stream(array).mapToInt(Integer::intValue));
    }
31267
public static <E> E one(E[] array) {
        return new OneElement<E>().apply(new ArrayIterator<>(array));
    }
914408
public static <T, J extends Convertable<T>> ArrayList<T> convert(J[] array) {
        return convert(array == null ? null : Arrays.asList(array));
    }
1297559
public static <T> Set<T> setOf(T... objects) {
        if (objects == null || objects.length == 0) {
            return Collections.emptySet();
        }
        return new HashSet<>(Arrays.asList(objects));
    }
529480
public static <A> Set<A> set(A... elements) {
        final Set<A> set = new HashSet<A>(elements.length);
        for (A element : elements) {
            set.add(element);
        }
        return set;
    }
1293835
private static Set<String> setFor( String... elements ) {
        Set<String> set = new HashSet<String>(elements.length);
        set.addAll(Arrays.asList(elements));

        return set;
    }
1114965
public static function unique($array)
    {
        $suitable = true;
        foreach ($array as $k => &$v) {
            if (is_array($v)) {
                $v = self::unique($v);
            } elseif (!is_int($k)) {
                $suitable = false;
            }
        }

        return $suitable ? self::uniqueFlat($array) : $array;
    }
676566
public static <T> T randomFrom(T[] array) {
    checkArgument(isNotEmpty(array), "Array cannot be empty");
    return IterableUtils.randomFrom(Arrays.asList(array));
  }
421600
function unique(array) {
    "use strict";
    var o = {},
        r = [];
    for (var i = 0, len = array.length; i !== len; i++) {
        var d = array[i];
        if (typeof o[d] === "undefined") {
            o[d] = 1;
            r[r.length] = d;
        }
    }
    return r;
}
729085
public static int[] unique(int[] arrays, int min, int max) {
        List<Integer> list = new ArrayList<>(arrays.length);
        for (int arr : arrays) {
            if (!list.contains(arr) && arr >= min && arr <= max) {
                list.add(arr);
            }
        }
        int[] res = new int[list.size()];
        int i = 0;
        for (int arr : list) {
            res[i++] = arr;
        }
        return res;
    }
799897
@SafeVarargs
    public static <T> Set<T> asSet(T... array) {
        Set<T> set = null;
        if (array != null) {
           set = new HashSet<>(Arrays.asList(array));
        }
        return set;
    }
1331814
public static Object toPrimitiveArray(Object array) {
    if (!array.getClass().isArray()) {
      throw new IllegalArgumentException("Must give array object.");
    }
    if (isWrapperArray(array.getClass())) {
      int length = Array.getLength(array);
      Object newArray = Array.newInstance(toPrimitive(array.getClass().getComponentType()), length);
      for (int i = 0; i < length; i++) {
        Array.set(newArray, i, Array.get(array, i));
      }
      return newArray;
    } else if (array.getClass().getComponentType().isArray()) {
      int length = Array.getLength(array);
      Object newArray = Array.newInstance(toPrimitiveArray(array.getClass().getComponentType()), length);
      for (int i = 0; i < length; i++) {
        Array.set(newArray, i, toPrimitiveArray(Array.get(array, i)));
      }
      return newArray;
    }
    return array;
  }
384211
public final static Object toObjectArray(final Object array) {
        if (!array.getClass().isArray()) {
            return array;
        }
        final Class<?> clazz = PRIMITIVE_TO_OBJ.get(array.getClass().getComponentType());
        return setArray(clazz, array);
    }