I have two ArrayLists (list1 and list2). I would like to see if in list 1 there are 1 (or more) objects in list2 (which are strings).
So for some examples:
List<String> list1 = Arrays.asList("ABCD", "EFGH", "IJKL", "QWER");
List<String> list2 = Arrays.asList("ABCD", "1234");
//Should result in true, because "ABCD" is in list 1 & 2
However, the thisAll () method does not work in this use case, since it 1234does not appear in list1 and leads to the result false, it also contains () does not work.
Besides writing my own implementation (comparing all values โโseparately from list2 to list1), is there a similar contains () method where a list of strings can be passed and compare them with another list and return true if one or more values โโare contained in this list ?
Additional examples:
ArrayList list1 = {1, 2, 3, 4, 5}
ArrayList list2 = {1, 2, 3} --> True
ArrayList list2 = {3, 2, 1} --> True
ArrayList list2 = {5, 6, 7, 8, 9} --> True
ArrayList list2 = {6, 7, 8, 9} --> False
source
share