Option 1 will not work for read-only lists, such as those returned by Arrays.asList .
Also, remove from an ArrayList is a significant cost when the list is long, since most of the support array needs to be copied.
Option 2 will work for all lists.
This is also a template that we recommend using with threads:
List<String> l = Arrays.asList("A","B","C"); List<String> filtered = l.stream() .filter(s -> s.equals("A")) .collect(Collectors.toList());
IMHO - use this one. The savings in option 1 are illusory.
source share