Java Median calculateMedianOfArrayListInteger(List integerList)

Here you can find the source of calculateMedianOfArrayListInteger(List integerList)

Description

calculate Median Of Array List Integer

License

LGPL

Declaration

public static Double calculateMedianOfArrayListInteger(List<Integer> integerList) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Collections;

import java.util.List;

public class Main {
    public static Double calculateMedianOfArrayListInteger(List<Integer> integerList) {
        if (integerList.size() > 1) {

            Collections.sort(integerList);
            double median;
            int middle = ((integerList.size()) / 2);
            if (integerList.size() % 2 == 0) {
                int medianA = integerList.get(middle);
                int medianB = integerList.get(middle - 1);
                median = Double.valueOf((medianA + medianB) / 2);
            } else {
                median = Double.valueOf(integerList.get(middle + 1));
            }/*from  w  w w . jav a  2 s.c o m*/
            return median;
        } else {
            return Double.NaN;
        }
    }
}

Related

  1. calcMedian(final double[] values)
  2. getMedian(double array[])
  3. getMedian(double[] a)
  4. getmedian(double[] vals, int nvalindex)
  5. getMedian(int[] array)