Java List Mean mean(List values)

Here you can find the source of mean(List values)

Description

mean

License

Open Source License

Declaration

public static double mean(List<Double> values) 

Method Source Code

//package com.java2s;
/* *********************************************************************** *
 * project: org.matsim.*//from w ww.  j  ava 2  s .  c  o m
 *                                                                         *
 * *********************************************************************** *
 *                                                                         *
 * copyright       : (C) 2012 by the members listed in the COPYING,        *
 *                   LICENSE and WARRANTY file.                            *
 * email           : info at matsim dot org                                *
 *                                                                         *
 * *********************************************************************** *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *   See also COPYING, LICENSE and WARRANTY file                           *
 *                                                                         *
 * *********************************************************************** */

import java.util.List;

public class Main {
    public static double mean(List<Double> values) {
        double sum = 0.0;
        int cnt = 0;
        if (values.size() == 0)
            return 0.0;
        for (Double value : values) {
            sum += value;
            cnt++;
        }
        return sum / cnt;
    }
}

Related

  1. mean(List data)
  2. mean(List list)
  3. mean(List list)
  4. mean(List vals)
  5. mean(List values)
  6. mean(List values)
  7. mean(List numbers)
  8. meanAbsolute(List vector)
  9. meanDouble(List list)