Showing posts with label array to hashset. Show all posts
Showing posts with label array to hashset. Show all posts

Wednesday, 27 May 2015

How to convert array to HashSet

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

public class ArrayToHashSet {
    public static void main(String[] args) {

        String[] arr = { "one", "two", "third" };
       

        Set<String> hs = new HashSet<String>(Arrays.asList(arr));

        // print hashset

        System.out.println("hashset is =" + hs);

    }
}

Output:

hashset is =[two, one, third]