How to find avearge in Collection of integers in Java using Stream API

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FindAverage {
    public static void main(String[] args) {

        List<Integer> nums = new ArrayList<>(Arrays.asList(1, 2, 5, 6, 18, 22, 33, 14, 0));
        double listAvg = nums.stream()
                .mapToDouble(num -> num)
                .average()
                .getAsDouble();

        System.out.println(listAvg); // will return 11.222222222222221
    }
}

How to print list separated by comma in Java

import java.util.ArrayList;
import java.util.stream.Collectors;

public class CommaDelimeter {
    public static void main(String[] args) {
        ArrayList<Integer> collectNums = new ArrayList<Integer>();
        collectNums.add(2);
        collectNums.add(9);
        collectNums.add(12);

        String joined = collectNums.stream()
                .map(Object::toString)
                .collect(Collectors.joining(", "));

        System.out.println(joined);
    }
}