Here you can find the source of toSet(T[] array)
Parameter | Description |
---|---|
T | the type |
array | the array to convert |
public static <T> Set<T> toSet(T[] array)
//package com.java2s; import java.util.Collections; import java.util.HashSet; import java.util.Set; public class Main { /**// w ww. j a v a2 s .co m * Converts an array to a {@link Set}. * * @param <T> the type * @param array the array to convert * @return the {@link Set} */ public static <T> Set<T> toSet(T[] array) { final Set<T> result = new HashSet<T>(); for (final T element : array) { result.add(element); } return Collections.unmodifiableSet(result); } }