Java 8 Collectors.averagingDouble() Example

AveragingDouble/Long/Int is a collector that simply returns an average of extracted elements.
Learn Java 8 at

Java Collectors Example: Getting Product Average Price

import java.util.List;  
import java.util.ArrayList;  
class Product{  
    int id;  
    String name;  
    float price;  
    public Product(int id, String name, float price) {  = id;  = name;  
        this.price = price;  
public class CollectorsExample {  
    public static void main(String[] args) {  
        List<Product> productsList = new ArrayList<Product>();  
        //Adding Products  
        productsList.add(new Product(1,"HP Laptop",25000f));  
        productsList.add(new Product(2,"Dell Laptop",30000f));  
        productsList.add(new Product(3,"Lenevo Laptop",28000f));  
        productsList.add(new Product(4,"Sony Laptop",28000f));  
        productsList.add(new Product(5,"Apple Laptop",90000f));  
        Double average =  
        System.out.println("Average price is: "+average);  
Average price is: 40200.0

Java 8 Tutorials