Java – How to check if an ArrayList contains any elements from an array of Strings

androidandroid-activityarraylistarraysjava

Within Android, I'd like to perform an if statement to check whether an ArrayList contains any element from an array of Strings?
e.g.

Check whether any of the elements from singingGroup are also containined in Winners[]

String Winners[] = {"Jennifer", "Steven", "Peter", "Parker"};

ArrayList<String> singingGroup  = new ArrayList<String>();

singingGroup.add("Patrick");

singingGroup.add("Jane");

singingGroup.add("Joe");

singingGroup.add("Susan");

singingGroup.add("Amy");

How can I do this? as I know how to check if one item is contained as in another array as below. But not if any from one, exist in another.

if (Arrays.asList(Winners).contains(singingGroup)) {

Best Solution

You can use

Collections.disjoint(singingGroup, Arrays.asList(Winners));

to test, is the 2 arguments have no common element(s) in common. (see also javadoc)

The negation of the result seems to be what you're looking for.