Finding whether a set and an array have any strings in common I have the following code.  It looks through an array, called items, and checks to see if there are any items in that array that also exist in a certain set of strings, called stringSet.

    Set&lt;String&gt; stringSet = new HashSet&lt;&gt;();
    stringSet.add("A");
    stringSet.add("B");
    stringSet.add("C");

    String[] items = new String[2];
    items[0] = "A";
    items[1] = "D";

    boolean hasValue = false;

    for (String item : items) {
        if (stringSet.contains(item)) {
            hasValue = true;
        }
    }
    System.err.println(hasValue);


Is there any way to avoid using a for each loop to achieve same result in Java 8, like with a stream, a map, etc.?
You can use the following stream in place of for-loop

Arrays.stream(items)
            .anyMatch(stringSet::contains);


What you are trying to do is loop through the items, and any time the item is contained in the string set u want to return true. 
anyMatch function breaks as soon as any of the items returns true