Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
