HashSet String. HashSet O(1) . O(n), , (.contains) .
, :
List<A> listA ...
Set<String> setB = new HashSet<>(); // populate setB
List<A> filteredA =
listA.stream()
.filter(a -> setB.contains(a.x)).collect(toList());
Also see this answer for some specific evidence of performance differences.
source
share