- 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
Java Program to convert int array to IntStream
To convert int array to IntStream, let us first create an int array:
int[] arr = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
Now, create IntStream and convert the above array to IntStream:
IntStream stream = Arrays.stream(arr);
Now limit some elements and find the sum of those elements in the stream:
IntStream stream = Arrays.stream(arr); stream = stream.limit(7); System.out.println("Sum of first 7 elements = "+stream.sum());
The following is an example to convert int array to IntStream:
Example
import java.util.Arrays; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { int[] arr = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; System.out.println("Array elements..."); for (int res : arr) { System.out.println(res); } IntStream stream = Arrays.stream(arr); stream = stream.limit(7); System.out.println("Sum of first 7 elements = "+stream.sum()); } }
Output
Array elements... 10 20 30 40 50 60 70 80 90 100 Sum of first 7 elements = 280
Advertisements