List of usage examples for java.util.stream Collectors averagingInt
public static <T> Collector<T, ?, Double> averagingInt(ToIntFunction<? super T> mapper)
From source file:Main.java
public static void main(String[] args) { Stream<String> s = Stream.of("1", "2", "3"); double o = s.collect(Collectors.averagingInt(n -> Integer.parseInt(n))); System.out.println(o);// ww w . j a va 2s. c o m }
From source file:Main.java
public static void main(String... args) { double o = Food.menu.stream().collect(Collectors.averagingInt(Food::getCalories)); System.out.println(o);//w w w .j a va2s. c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { List<Person> persons = Arrays.asList(new Person("Max", 18), new Person("Peter", 23), new Person("Pamela", 23), new Person("David", 12)); Double averageAge = persons.stream().collect(Collectors.averagingInt(p -> p.age)); System.out.println(averageAge); // 19.0 }