
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
IntStream limit() Method in Java
The limit() method of the IntStream class is used to return a stream consisting of the elements of this stream, truncated to be no longer than maxSize in length. Here, maxSize is the parameter.
The syntax is as follows
IntStream limit(long maxSize)
Here, the maxSize parameter is the count of elements the stream is limited to.
At first, an IntStream is created with the range() method to set a sequential order of elements
IntStream intStream = IntStream.range(20, 40);
Now, use the limit() method, whose parameter is the maxSize i.e. the count of elements the stream is limited to
intStream.limit(8)
The following is an example to implement IntStream limit() 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(20, 40); intStream.limit(8).forEach(System.out::println); } }
Output
20 21 22 23 24 25 26 27
Advertisements