> For the complete documentation index, see [llms.txt](https://muhammad-tri-wibowo.gitbook.io/java-tutorials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://muhammad-tri-wibowo.gitbook.io/java-tutorials/lambda/filtering-mapping-reducing.md).

# Filtering, Mapping, Reducing

**Simple Lambda Examples (Filtering, Mapping, Reducing):**

1. **Filtering with Lambda:**

   ```java
   List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
   List<Integer> evenNumbers = numbers.stream().filter(num -> num % 2 == 0).collect(Collectors.toList());
   System.out.println(evenNumbers); // Output: [2, 4]
   ```
2. **Mapping with Lambda:**

   ```java
   List<String> words = Arrays.asList("hello", "world", "java");
   List<Integer> wordLengths = words.stream().map(str -> str.length()).collect(Collectors.toList());
   System.out.println(wordLengths); // Output: [5, 5, 4]
   ```
3. **Reducing with Lambda:**

   ```java
   List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
   int sum = numbers.stream().reduce(0, (a, b) -> a + b);
   System.out.println(sum); // Output: 15
   ```

In these examples, lambda expressions are used to define the behavior passed to higher-order functions like `filter()`, `map()`, and `reduce()` in Java streams. The lambda expressions make the code concise and expressive, allowing developers to focus on the logic specific to their application rather than boilerplate code.
