Implement Filter Function using Reduce in Java 8 Streams Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report Many times, we need to perform operations where a stream reduces to a single resultant value, for example, maximum, minimum, sum, product, etc. Reducing is the repeated process of combining all elements. reduce operation applies a binary operator to each element in the stream where the first argument to the operator is the return value of the previous application and the second argument is the current stream element. In this article, we are going to Implement the Filter Function using Reduce in Java 8 Streams. Given a list of Integers, PRINT a list of Even Numbers present in the list using Reduce function in Java 8 Streams. INPUT : [1, 2, 3, 4, 5,6, 7] OUTPUT : [2, 4, 6] INPUT : [1, 7, 9] OUTPUT : [] Recommended: Please try your approach on {IDE} first, before moving on to the solutiion The idea used here is that we know a reduce function helps in summing numbers, concatenating strings, etc., or in general, accumulating objects. So as an accumulator we have an array that is initially empty and when an element satisfies the condition, it gets added to the array. Java /*package whatever //do not write package name here */ import java.io.*; import java.util.*; import java.util.stream.*; class GFG { public static void main(String[] args) { List<Integer> arr = List.of(1, 2, 3, 4, 5, 6, 7); List<Integer> even = arr.stream().reduce(new ArrayList<Integer>(), (a, b) -> { if (b % 2 == 0) a.add(b); return a; }, (a, b) -> { a.addAll(b); return a; }); System.out.println(even); } } Output[2, 4, 6] Create Quiz Comment P pankajcodehere Follow 2 Improve P pankajcodehere Follow 2 Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2022 Java 8 +1 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like