Skip to main content

Posts

Showing posts with the label filter()

Java 8 Stream API Filter() Method with Examples | Programming Blog

Java 8 Stream Filter with Lambda Expression Java 8 Stream Filter() method with Examples What is Filter in Java Stream?      Simply, as a name suggest it filters data based on given predicate (boolean) Condition. The condition is applied to all element of Stream, and those who satisfied the condition moves to next stage and those who does not pass filtered out. For example, If you want to filter list of Integer based on greater than some value or if you want to get even or odd data then you can easily filtered out. Stream Filter() method is Intermediate Operation. If you want to learn about difference between Intermediate and Terminal operation check out:- Difference between Intermediate and Terminal Operation The benefit of using filter() method is lazy evaluation. Means no data comparison is performed unless you call a terminal operation like forEach() or Collect() . We will use Lambda expression for filter elements based on given Predicate. Learn more about Lambda Expr...