How to solve "add all in list cannot be applied to"

FYI Stream.of(listRef) will give back List<Results> and there is no method .getTitle() on List. I think you mean to do listRef.stream().filter... instead of Stream.of(listRef).filter...

Anyways, this is a standard example which demonstrates that you shouldn't use streams for every operation. You can reduce the streams to:

listRef.removeIf(results -> !results.getTitle().contains(query.toString().toLowerCase()));
filteredListIn.addAll(listRef);

Note: .removeIf will effectively operate on listRef so you should clone if required.


You have to collect all stream elements in a list in order to add it to a collection:

filteredListIn.addAll(listRef.stream()
  .filter(results -> results.getTitle().contains(query.toString().toLowerCase()))
  .collect(Collectors.toList());

addAll expects a Collection parameter. As long as a stream is not collected, it is of type Stream which is independent of Collection. Other answers give you a simple solution: collect to a list, then add this list.

I want to mention though that this is not the most efficient solution and introduces quite some memory overhead: the stream is first collected to a new list, then all items of this list are copied to your existing list, and eventually the garbage collector will free the occupied space of the temporary list.

This overhead (allocating memory for the backing array of the temporary list) can be avoided by not collecting the stream, but iterating over its elements with the forEach terminal operation:

Stream.of(listRef)
        .filter(results -> results.getTitle().contains(query.toString().toLowerCase()))
        .forEach(filteredListIn::add);

If your list is empty to begin with, the best solution is to collect it directly:

final List<...> filteredListIn = Stream.of(listRef)
        .filter(results -> results.getTitle().contains(query.toString().toLowerCase()))
        .collect(Collectors.toList()); // or .toUnmodifiableList