- Trending Categories
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
LongStream generate() method in Java
The generate() method of the LongStream class returns an infinite sequential unordered stream where each element is generated by the provided LongSupplier.
The syntax is as follows:
static LongStream generate(LongSupplier s)
Here, s is the LongSupplier for generate elements. The LongSupplier is the supplier of long-valued results.
To use the LongStream class in Java, import the following package:
import java.util.stream.LongStream;
The following is an example to implement LongStream generate() method in Java −
Example
import java.util.stream.LongStream; public class Demo { public static void main(String[] args){ LongStream longStream = LongStream.generate(() -> { return (long)(Math.random() * 100); }); System.out.println("Unordered Stream..."); longStream.limit(3).forEach(System.out::println); } }
output
Unordered Stream... 79 43 18
Advertisements