package nilpointer.net;
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(String[] args) {
List<Integer> numbers = new ArrayList<Integer>();
numbers.add(5);
numbers.add(2);
numbers.add(11);
numbers.add(-9);
numbers.add(7);
numbers.add(-4);
double avg1 = numbers.stream().mapToInt(p -> p).average().getAsDouble();
System.out.println("avg 1: " + avg1);
double avg2 = numbers.stream().filter(p -> p > 0).mapToInt(p -> p).average().getAsDouble();
System.out.println("avg 2: " + avg2);
}
}
avg 1: 2.0
avg 2: 6.25