Convert Object Array to Set - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

Convert Object Array to Set

Demo Code


//package com.java2s;

import java.util.Arrays;
import java.util.HashSet;

import java.util.Set;

public class Main {
    public static void main(String[] argv) {
        Object[] tArray = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out.println(setArray2Set(tArray));
    }//w ww .java 2 s  . com

    public static Set<?> setArray2Set(Object[] tArray) {
        Set<?> tSet = new HashSet(Arrays.asList(tArray));
        return tSet;
    }
}

Related Tutorials