Java Streams

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/44

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:25 PM on 4/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

45 Terms

1
New cards

Stream

Not a data structure, it doesn’t store data. Instead, it’s a pipeline for processing data.

2
New cards

Takes input like collection, array, and etc.
Applies operations like filter, map, and etc.
Produces output like result or side effect

A stream

3
New cards

No Storage
Functional Style
Lazy Evaluation

Characteristics of java stream.

4
New cards

No Storage

The stream doesn’t copy the list, it just references it.

5
New cards

Functional Style

Instead of how to do it, you describe what to do.

6
New cards

Lazy Evaluation

Nothing runs until a terminal operation is called.

7
New cards

From Collections
Primitive Streams
Infinite Streams

Different ways in creating steam

8
New cards

From Collections

Most common use-case.

9
New cards
List<String> names = List.of("Alice", "Bob");
names.stream();

Sample :
	List<String> upperNames = names.stream() // create stream
.map(String::toUpperCase) // intermediate operation
.collect(Collectors.toList()); // terminal operation

System.out.println(upperNames);
output: [ALICE, BOB]

Example of From Collection.

10
New cards

Boxing

Converting primitive to wrapper object.

11
New cards

Unboxing

Converting wrapper object to primitive.

12
New cards

Infinite Streams

This don’t end, unless you limit them

13
New cards

.filter()

An intermediate operation in Java Streams that keeps only the elements that match a given condition.

14
New cards

filter()

Keeps elements that match a condition.

15
New cards

.map()

An intermediate operation in Java Streams that transforms each element of the stream into a new form.

16
New cards

flatMap()

An intermediate operation in Java Streams that flattens nested structures into a single stream.

17
New cards

forEach()

Consumes the stream.

18
New cards

collect()

Converts stream into a collection.

19
New cards

Creates container
Adds element
Merges results that is important for parallel

Process of the collect().

20
New cards

Reduce()

Combines elements into one value.

21
New cards

groupingBy()

It is a Collector that groups elements of a stream into a Map based on a key. Groups elements into a Map.

22
New cards

joining()

Combines strings efficiently (better than +)

23
New cards

Handle mutable containers safely
Work with parallel streams

Why Collectors Matter?

24
New cards

parallelStream()

Splits work across multiple threads.

25
New cards
List<Integer> result = new ArrayList<>();
parallelStream().forEach(result::add);

Avoid this when using parallelStream() because it is not thread-safe

26
New cards

Each thread gets its own container
Then merges safely

Why collect() Works?

27
New cards
Optional<T>

Streams often return thus and its value may be present OR absent.

28
New cards
employees.stream()
.filter(e -> e.salary > 50000)

Remove unwanted data early (performance benefit)

29
New cards
.sorted(...)

Sorting is expensive → done after filtering

30
New cards
.map(e -> e.name)

Transform to required output

31
New cards
.collect(...)

Final result

32
New cards

Source
Intermediate
Terminal

Pipeline stages

33
New cards
list.stream()

Source

34
New cards
.filter().map()

Intermediate

35
New cards
.collect()

Terminal

36
New cards

Stream Reuse
Side Effects
Overusing Streams

Common Pitfalls

37
New cards

Stream Reuse

Streams are single-use

38
New cards

Side Effects

Breaks functional model

39
New cards

Overusing Streams

Streams are not always clearer

40
New cards

Supplier
Accumulator
Combiner

Custom Collector

41
New cards

Supplier

Creates container

42
New cards

Accumulator

Adds elements

43
New cards

Combiner

Merges results

44
New cards

peek()

used for Debugging only and Should not modify data.

45
New cards
.peek(System.out::println)

peek()

Explore top flashcards

flashcards
SAT Math
82
Updated 964d ago
0.0(0)
flashcards
Animal Science Chapter 5
44
Updated 797d ago
0.0(0)
flashcards
4b Politcal geohgrpahy
42
Updated 1117d ago
0.0(0)
flashcards
BANDAGING
37
Updated 372d ago
0.0(0)
flashcards
La Salud vocabulary
80
Updated 1127d ago
0.0(0)
flashcards
Chapter 12-Latin
50
Updated 872d ago
0.0(0)
flashcards
SAT Math
82
Updated 964d ago
0.0(0)
flashcards
Animal Science Chapter 5
44
Updated 797d ago
0.0(0)
flashcards
4b Politcal geohgrpahy
42
Updated 1117d ago
0.0(0)
flashcards
BANDAGING
37
Updated 372d ago
0.0(0)
flashcards
La Salud vocabulary
80
Updated 1127d ago
0.0(0)
flashcards
Chapter 12-Latin
50
Updated 872d ago
0.0(0)