Concept
Optional
๐ก Streams are single-use โ create a new stream for a second pipeline. Milestone: You completed Core APIs (chapters 16โ20).
Where it fits
Packages: Core Java (pkg1core)
Learn
Existing chapters for this concept.
- Streams & Optional
๐ก Streams are single-use โ create a new stream for a second pipeline. Milestone: You completed Core APIs (chapters 16โ20).
Open lesson โ
See it in code
Existing Java examples.
- core 23 Optional Demo
- Optional is a container that holds a value or nothing. - Prefer map/filter/flatMap + orElse/orElseThrow over isPresent()/get(). - Use it as a RETURN type;โฆ
Open example โ - core22StreamsDemo
- Streams are LAZY: intermediate ops (filter/map/sorted) build a pipeline; a terminal op (collect/reduce/forEach/count) triggers execution. - Streams don'tโฆ
Open example โ
Prepare
Existing interview questions.
- What is `Optional`?
Clear naming, small methods, immutability, proper exceptions, tests, and idiomatic APIs.
Open question โ - Builder pattern for many optional parameters?
Telescoping constructors are unreadable; Builder scales with fluency and validation.
Open question โ
Java versions
- Optional
Optional. Optional is a return type for a value that may be absent. The stream chapter covers how to use it.
Open version note โ
Related concepts
Only explicit or deterministic relationships from the concept model.