- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream peek() method in Java
The syntax is as follows
DoubleStream peek(DoubleConsumer action)
Here, DoubleConsumer is an operation that accepts a single double-valued argument and returns no result.
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
The following is an example to implement DoubleStream peek() method in Java
Example
import java.util.*; import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(28.7, 35.6, 48.3, 69.8, 75.8, 80.5, 90.8); System.out.println("Elements in the stream..."); long num = doubleStream.peek(System.out::println).count(); System.out.println("Number of elements in the stream = " + num); } }
Output
Elements in the stream... 28.7 35.6 48.3 69.8 75.8 80.5 90.8 Number of elements in the stream = 7
Advertisements