Convert object array to Set - Android java.util

Android examples for java.util:Set

Description

Convert object array to Set

Demo Code


//package com.book2s;

import java.util.HashSet;

import java.util.Set;

public class Main {

    public static <T> Set<T> toSet(T[] array) {
        HashSet<T> set = new HashSet<T>();

        if (array != null) {
            for (T object : array) {
                set.add(object);/*from  w  w w . j av  a 2  s . c  o m*/
            }
        }

        return set;
    }
}

Related Tutorials