![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
IntStream range() method in Java
The range() method in the IntStream class in Java is used to return a sequential ordered IntStream from startInclusive to endExclusive by an incremental step of 1. This includes the startInclusive as well.
The syntax is as follows −
static IntStream range(int startInclusive, int endExclusive)
Here, the parameter startInclusive includes the starting value, whereas endExclusive excludes the last value
To work with the IntStream class in Java, import the following package −
import java.util.stream.IntStream;
Create an IntStream and add stream elements in a range using range() method. This returns a sequential ordered IntStream by an incremental step of 1 within the range −
intStream.forEach(System.out::println);
The following is an example to implement IntStream range() 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, 30); intStream.forEach(System.out::println); } }
Output
20 21 22 23 24 25 26 27 28 29
Advertisements