Peek
Peek is an operation that observes the next or otherwise accessible element without consuming, removing, or advancing past it.
Kafka Streams in Action, Second Edition
KStream.peek is a Kafka Streams operation that performs a stateless action on each record without changing the record's key or value.
- How it is used
- Provides development-time visibility into records without interrupting a Kafka Streams topology.
- How deep it goes
- Explains callback behavior, unchanged records, chaining, and windowed-result inspection without descending into processor internals.
- Examples
- Uses the Yelling app and windowed aggregation logging to inspect records before transformations and analyze window boundaries.
- What you can do after
- Apply it via Kafka Streams to print, log, or collect records while continuing a KStream chain.
Read how Kafka Streams in Action, Second Edition explains peek →
100 Java Mistakes and How to Avoid Them
A peek operation is a Stream intermediate operation that applies a supplied Consumer to elements as they pass through the pipeline without changing their values.
- How it is used
- Uses a Consumer for observational side effects, chiefly debugging within a Stream pipeline.
- How deep it goes
- Explains side effects, short-circuiting, parallel execution, and optimization limits without descending into Stream implementation internals.
- Examples
- Uses trimming, external collection, filtering, limit(5), count, and separate streams to expose incomplete side effects.
- What you can do after
- Diagnose/debug pipeline traversal with peek and replace fragile side effects using explicit stream operations.
Read how 100 Java Mistakes and How to Avoid Them explains peek →
Grokking Data Structures
A peek operation returns the top element of a stack without removing it or changing the stack's structure.
- How it is used
- Supports inspecting a stack’s next element without removing it or changing its structure.
- How deep it goes
- Explains empty checks, private-attribute access, mutable results, copying, and public accessors, then assigns implementation exercises.
- Examples
- Uses a pile-of-dishes analogy, Python linked-list code, deepcopy, get(i), and exercises comparing linked-list and dynamic-array stacks.
- What you can do after
- Build it from scratch by implementing peek, handling empty stacks, protecting mutable values, and replacing private access with get(i).
Also covered in
- Advanced Algorithms and Data Structures
- Write Powerful Rust Macros
- Clojure: The Essential Reference
- Latency
What to know first
- vectorA vector is an indexed sequence of elements, typically stored contiguously and often capable of changing size during program execution.
- queueA queue is an ordered collection or buffer that holds items awaiting retrieval or processing according to a defined ordering policy, commonly first-in, first-out.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
Related concepts
- side effectuses · A side effect is an observable change or interaction caused by a computation beyond producing its direct result, such as modifying state or interacting with the external environment.
- stackpart of · A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
- topcontrasts with · The top operation accesses the element currently having the highest priority in a priority queue or heap.
- dequeuecontrasts with · Dequeue is a queue operation that removes the next item according to the queue’s ordering policy and typically returns it.
- TempDatauses · TempData is an ASP.NET Core temporary-data dictionary for storing values across requests, commonly through cookies.
Questions about peek
What is peek?
Peek is an operation that observes the next or otherwise accessible element without consuming, removing, or advancing past it.
Which Manning books explain peek?
Kafka Streams in Action, Second Edition, 100 Java Mistakes and How to Avoid Them and Grokking Data Structures.
What should I know before learning peek?
Manning books that teach peek usually introduce vector, queue and array first.
What is the difference between peek and top?
Peek is an operation that observes the next or otherwise accessible element without consuming, removing, or advancing past it. The top operation accesses the element currently having the highest priority in a priority queue or heap.
What is peek part of?
Peek is part of stack. A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


