Here you can find the source of getStandardDeviation(List
public static double getStandardDeviation(List<Double> data)
//package com.java2s; //License from project: GNU General Public License import java.util.List; public class Main { public static double getStandardDeviation(List<Double> data) { // sd is sqrt of sum of (values-mean) squared divided by n - 1 // Calculate the mean double mean = 0; final int n = data.size(); if (n < 2) { return Double.NaN; }/* www . ja v a 2s.c o m*/ for (int i = 0; i < n; i++) { mean += data.get(i); } mean /= n; // calculate the sum of squares double sum = 0; for (int i = 0; i < n; i++) { final double v = data.get(i) - mean; sum += v * v; } // Change to ( n - 1 ) to n if you have complete data instead of a sample. return Math.sqrt(sum / (n - 1)); } }