package stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamExample09 {
    public static void main(String[] args) {
        // averagingLong
        List<Long> numbers = Arrays.asList(1L, 2L, 3L, 4L, 5L);
        double averagingLongNumbers = numbers.stream()
                .collect(Collectors.averagingLong(Long::longValue));
        System.out.println("Average: " + averagingLongNumbers);

        // averagingDouble
        List<Double> averagingDoubleNumbers = Arrays.asList(1.5, 2.5, 3.5, 4.5, 5.5);
        double averagingDouble = averagingDoubleNumbers.stream()
                .collect(Collectors.averagingDouble(Double::doubleValue));
        System.out.println("Average: " + averagingDouble);

        // averagingInt
        List<Integer> averagingIntNumbers = Arrays.asList(1, 2, 3, 4, 5);
        double averagingInt = averagingIntNumbers.stream()
                .collect(Collectors.averagingInt(Integer::intValue));
        System.out.println("Average: " + averagingInt);
    }
}