I am having lists of String
type say list aLista
and bListb
first list might have at max 10 elements
however bListb
might have thousand or even more elements. Now i have to find all elements from aList
which are not in bListb
. Here is my approach
List<String> aLista = Arrays.asList("Anil","Abhishek","Ritu");
List<String> bListb = Arrays.asList("g","o","e","Abhishek","Ritu");
List<String> result3 = aLista.stream().filter(al ->
!bListb.contains(al)).collect(Collectors.toList());
System.out.println(result3);
// output Anil
But i am not sure about performance as bListb
might have much elements later on . So i just came to know about best optimum way of doing this. thanks for your time.