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

troyal picture troyal · Apr 30, 2009 · Viewed 15.2k times · Source

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

Answer

Dan Lew picture Dan Lew · Apr 30, 2009

Use Collection.containsAll():

boolean isSubset = listA.containsAll(listB);