You can use the map function to square the number and then filter to avoid numbers which are less than 10000.We will use average as terminating function in this case.
import java.util.Arrays; import java.util.List; import java.util.OptionalDouble; public class RemoveDuplicatesFromListMain { public static void main(String[] args) { Integer[] arr=new Integer[]{100,24,13,44,114,200,40,112}; List<Integer> list = Arrays.asList(arr); OptionalDouble average = list.stream() .mapToInt(n->n*n) .filter(n->n>10000) .average(); if(average.isPresent()) System.out.println(average.getAsDouble()); } }
output:
21846.666666666668
Don't miss the next article!
Be the first to be notified when a new article or Kubernetes experiment is published.
Share This