Hackforge Academy

Category: java

Streams in Java

Published on 24 Feb 2026

Explanation


Stream is used to process collections in
functional style.

Code:

List<Integer> list = Arrays.asList(1,2,3);

Explanation


filter() is used to filter elements.

Code:

list.stream()
.filter(n -> n>1)
.forEach(System.out::println);

Explanation


map() transforms elements.

Code:

list.stream()
.map(n -> n*2)
.forEach(System.out::println);

Explanation


collect() gathers stream results into a
collection.

Code:

List<Integer> result = 
list.stream().collect(Collectors.toList());

Explanation


reduce() performs aggregation operations.

Code:

int sum = list.stream().reduce(0,(a,b)->a+b);

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community