How can I easily check to see whether all the elements in one ArrayList are all elements of another ArrayList?
Asked
Active
Viewed 1.8k times
2 Answers
48
boolean isSubset = listA.containsAll(listB);

Dan Lew
- 85,990
- 32
- 182
- 176
-
is there anything available so that a new array is generated containing all data that's shared in listA and listB? Object[] subset = listA.shared(listB) – Someone Somewhere May 24 '11 at 23:34
-
2Set common = new HashSet(listA); common.retainAll(listB); // now "common" contains only the common elements – JimN Aug 02 '11 at 02:04
-
Is there a way to check for the order of the elements as well? I tried this and it was true even though I'd changed the order of the elements. Is there a way to do what I'd like to do? – CodingInCircles Apr 02 '13 at 20:39
-
How to check if ATLEAST ONE of the elements of a String ArrayList are contained in another String ArrayList?? – Shikhar Mar 18 '19 at 04:50
-
1As this is case sensitive, how to validate for case insensitive lists? – Brooklyn99 Nov 06 '19 at 23:21