📘 Lesson · Lesson 44
Stream API
Stream API
What is the Stream API?
The Stream API processes collections in a clean pipeline — filter, transform and collect data without manual loops.
Example
import java.util.*;
import java.util.stream.*;
List<Integer> nums = Arrays.asList(1,2,3,4,5,6);
List<Integer> result = nums.stream()
.filter(n -> n % 2 == 0) // keep even
.map(n -> n * n) // square them
.collect(Collectors.toList());
System.out.println(result); // [4, 16, 36][4, 16, 36]
Summary
filter()keeps items,map()transforms,collect()gathers results.- Streams make collection processing short and readable.
Stream API क्या है?
Stream API collections को साफ pipeline में process करता है — manual loops बिना filter, transform और collect करें।
Example
import java.util.*;
import java.util.stream.*;
List<Integer> nums = Arrays.asList(1,2,3,4,5,6);
List<Integer> result = nums.stream()
.filter(n -> n % 2 == 0) // even रखें
.map(n -> n * n) // square करें
.collect(Collectors.toList());
System.out.println(result); // [4, 16, 36][4, 16, 36]
सारांश
filter()items रखता,map()transform,collect()results इकट्ठा करता है।- Streams collection processing को छोटा और पढ़ने योग्य बनाते हैं।