top of page
Search

Java 8 Stream - filter and map Example

  • schick09
  • May 21, 2024
  • 1 min read

We've talked about using java.util.stream.forEach and java.util.stream.anyMatch in prior posts.  Today we're going to talk about the filter and map features of the java.util.stream package.

 

The filter feature takes a Predicate and returns a java.util.stream consisting of data elements that matched that Predicate condition.

 

The map feature takes a custom function and returns a new java.util.stream consisting of the response from that function.

 

You can then use java.util.stream.collect and java.util.stream.collectors.toList() to reduce the stream to a java.util.List

 

 

For your reference, we have created a filter and map example you can take a look at here  -- https://github.com/daveschickconsulting/java_8_examples/blob/main/src/funwithjava8streams/MainExample_filterAndMap.java



 
 
 

Comments


Dave Schick Consulting

©2023 by Dave Schick Consulting. Proudly created with Wix.com

bottom of page