
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
LongStream forEach Method in Java
The forEach() method of the LongStream class in Java performs an action for each element of this stream.
The syntax is as follows
void forEach(LongConsumer action)
Here, the parameter action is a non-interfering action to perform on the elements. LongConsumer represents an operation that accepts a single long-valued argument and returns no result.
To use the LongStream class in Java, import the following package
import java.util.stream.LongStream;
The following is an example to implement LongStream forEach() method in Java
Example
import java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(1000L, 12000L, 30000L); longStream.forEach(System.out::println); } }
Output
1000 12000 30000
Advertisements