
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
IntStream peek() method in Java
The peek() method in the IntStream class in Java returns a stream consisting of the elements of this stream. It additionally performs the provided action on each element as elements are consumed from the resulting stream.
The syntax is as follows
IntStream peek(IntConsumer action)
Here, the parameter action is a non-interfering action to perform on the elements as they are consumed from the stream. The IntConsumer represents an operation that accepts a single int-valued argument and returns no result.
The following is an example to implement IntStream peek() method in Java
Example
import java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { IntStream intStream = IntStream.range(50, 60); System.out.println("Elements in the stream = "); long res = intStream.peek(System.out::println).count(); System.out.println("Count of elements = " + res); } }
Output
Elements in the stream = 50 51 52 53 54 55 56 57 58 59 Count of elements = 10
- Related Questions & Answers
- DoubleStream peek() method in Java
- LongStream peek() method in Java
- ArrayBlockingQueue peek() Method in Java
- IntStream asLongStream() method in Java
- IntStream forEachOrdered() method in Java
- IntStream asDoubleStream() method in Java
- IntStream rangeClosed() method in Java
- IntStream sorted() method in Java
- IntStream findFirst() method in Java
- IntStream map() method in Java
- IntStream flatMap() method in Java
- IntStream iterator() method in Java
- IntStream limit() method in Java
- IntStream parallel() method in Java
- IntStream builder() method in Java
Advertisements