Syntax error Map to create new value from int array in Java

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
Updated on: 2019-07-30T22:30:26+05:30

569 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements