Java - Write code to Returns true if the value is in the array, using HashSet

Requirements

Write code to Returns true if the value is in the array, using HashSet

Demo

//package com.book2s;
import java.util.*;

public class Main {
    public static void main(String[] argv) {
        String[] list = new String[] { "1", "abc", "level", null,
                "book2s.com", "asdf 123" };
        String value = "book2s.com";
        System.out.println(contains(list, value));
    }// ww  w. j a v  a 2s.  co m

    /**
     * Returns true if the value is in the list.
     * @param list
     * @param value
     * @return
     */
    public static boolean contains(final String[] list, final String value) {
        HashSet<String> set = new HashSet<String>(Arrays.asList(list));
        return set.contains(value);
    }
}

Related Exercise