Search code examples
javajava-8java-stream

Can we collect two lists from Java 8 streams?


Consider I have a list with two types of data,one valid and the other invalid.

If I starting filter through this list, can i collect two lists at the end?


Solution

  • Another suggestion: filter using a lambda that adds the elements that you want to filter out of the stream to a separate list.