- 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
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
- Related Articles
- Convert Character Array to IntStream in Java
- Program to convert IntStream to String in Java
- Program to convert String to IntStream in Java
- Java Program to convert a String to int
- Java Program to convert int to binary string
- Java Program to convert int to Octal String
- Java Program to convert mathematical string to int
- Java Program to convert an int value to String
- Convert IntStream to String in Java
- Convert String to IntStream in Java
- How to convert integer set to int array using Java?
- Convert String to Java int
- Java Program to write int array to a file
- Java Program to convert positive int to negative and negative to positive
- Convert int to String in Java

Advertisements