- 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
Map to create new value from int array in Java
Let’s say the following is our int array elements:
10, 50, 100, 200, 250, 300, 400, 500
Here, we are mapping and creating a new value by incrementing each int element with 1:
Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1)
Now find the average:
Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1).average()
The following is an example to Map and create new value from int array:
Example
import java.util.Arrays; public class Demo { public static void main(String[] args) throws Exception { Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1).average() .ifPresent(System.out::println); } }
Output
227.25
Advertisements