I want to iterate two lists and get new filtered list which will have values not present in second list. Can anyone help?
I have two lists - one is list of strings, and the other is list of
this.str = val;
List<String> list1 = Arrays.asList("abc", "xyz", "lmn");
List<MyClass> list2 = new ArrayList<MyClass>();
MyClass obj = new MyClass("abc");
obj = new MyClass("xyz");
Finally I got way to achieve this following way -
List<String> unavailable = list1.stream() .filter(e -> (list2.stream() .filter(d -> d.getStr().equals(e)) .count())<1) .collect(Collectors.toList());
But this is also working as expected. Please let me know how much this is effective? and if anyone has other way to do same thing?