There are 2 lists containing some string elements. These lists may be equal or there may be some missing elements in second list.
The task is to compare these 2 lists and to find a missing emlenet or missing elements in second list and print them.
There are 2 lists containing some string elements. These lists may be equal or there may be some missing elements in second list.
The task is to compare these 2 lists and to find a missing emlenet or missing elements in second list and print them.
You could try something like that:
public static List<String> ListDiff(List<String> a, List<String> b) {
return a.stream()
.filter(s->!b.contains(s))
.collect(Collectors.toList());
}
But note that if you were using Set
s instead of List
s, you could use removeAll
that would probably be much faster.
Basically, you need to check if each element of list 1 is in list 2 or not. It it's present, do nothing. If it's not, print it. I'm gonna solve this problem using python as that's what I'm good at haha.
Let us say your first list is ['A', 'B', 'C'] and the second list is ['A', 'B']. Then,
list1 = ['A', 'B', 'C']
list2 = ['A', 'B', 'C']
if list1 == list2:
print("Equal lists")
else:
for i in list1:
if i not in list2:
print(i)