Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether the elements of an ArrayList are all contained in another ArrayList

Tags:

How can I easily check to see whether all the elements in one ArrayList are all elements of another ArrayList?

like image 396
troyal Avatar asked Apr 30 '09 18:04

troyal


People also ask

How do you check if an ArrayList contains another ArrayList?

ArrayList. contains() method can be used to check if an element exists in an ArrayList or not. This method has a single parameter i.e. the element whose presence in the ArrayList is tested. Also it returns true if the element is present in the ArrayList and false if the element is not present.

How do you check if all items in a list are in another list Java?

The containsAll() method of List interface in Java is used to check if this List contains all of the elements in the specified Collection. So basically it is used to check if a List contains a set of elements or not.


1 Answers

Use Collection.containsAll():

boolean isSubset = listA.containsAll(listB); 
like image 108
Dan Lew Avatar answered Sep 21 '22 13:09

Dan Lew