Java Utililty Methods Median

List of utility methods to do Median

Description

The list of methods to do Median are organized into topic(s).

Method

doublecalcMedian(final double[] values)
Returns the median value of an array of double.
if (values == null) {
    throw new IllegalArgumentException("vector values == null!");
if (values.length == 0) {
    return 0D;
double rc;
Arrays.sort(values);
...
DoublecalculateMedianOfArrayListInteger(List integerList)
calculate Median Of Array List Integer
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);
...
doublegetMedian(double array[])
get Median
Arrays.sort(array);
return array[array.length / 2];
doublegetMedian(double[] a)
Returns the median of an array.
if (a.length == 0) {
    return 0;
double[] ary = Arrays.copyOf(a, a.length);
Arrays.sort(ary);
int mid = ary.length / 2;
if (ary.length % 2 == 1) {
    return ary[mid];
...
doublegetmedian(double[] vals, int nvalindex)
Returns the median value in vals in indicies between 0 and nvalindex-1
double dmedian;
Arrays.sort(vals, 0, nvalindex);
if (nvalindex % 2 == 0) {
    dmedian = (vals[nvalindex / 2 - 1] + vals[nvalindex / 2]) / 2;
} else {
    dmedian = vals[nvalindex / 2];
return dmedian;
...
floatgetMedian(int[] array)
get Median
if (array.length == 0)
    return 0;
Arrays.sort(array);
float median;
if (array.length % 2 == 0)
    median = ((float) array[array.length / 2] + (float) array[array.length / 2 - 1]) / 2;
else
    median = (float) array[array.length / 2];
...
doublegetMedianValue(ArrayList values)
get Median Value
if (values.isEmpty()) {
    return -1.0;
Collections.sort(values);
if (values.size() % 2 == 1) {
    return values.get(values.size() / 2 + 1);
double lower = values.get(values.size() / 2 - 1);
...
doublemedian(ArrayList v)
Return the median
Collections.sort(v);
if (v.size() % 2 == 1)
    return v.get((v.size() + 1) / 2 - 1);
else {
    double lower = v.get(v.size() / 2 - 1);
    double upper = v.get(v.size() / 2);
    return (lower + upper) / 2.0;
doublemedian(ArrayList values)
It calculates the median value of the given set of values
values.sort(null);
int middle = values.size() / 2;
if (values.size() % 2 == 1) {
    return values.get(middle);
} else {
    return (values.get(middle - 1) + values.get(middle)) / 2.0;
doubleMedian(ArrayList values)
Calculates the median value from a list of numeric values.
Collections.sort(values);
if (values.size() % 2 == 1)
    return values.get((values.size() + 1) / 2 - 1);
else {
    double lower = values.get(values.size() / 2 - 1);
    double upper = values.get(values.size() / 2);
    return (lower + upper) / 2.0;