Java Median median(final ArrayList values)

Here you can find the source of median(final ArrayList values)

Description

Compute median of a sorted list of Long s.

License

Open Source License

Parameter

Parameter Description
values sorted list of values.

Return

median of the values.

Declaration

private static long median(final ArrayList<Long> values) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    /**/*from   ww w .ja v a  2s  .  com*/
     * Compute median of a sorted list of {@link Long}s.
     *
     * @param values
     *            sorted list of values.
     * @return median of the values.
     */
    private static long median(final ArrayList<Long> values) {
        if (values.size() % 2 == 1)
            return values.get((values.size() + 1) / 2 - 1);
        final long lower = values.get(values.size() / 2 - 1);
        final long upper = values.get(values.size() / 2);

        return (lower + upper) / 2;
    }
}

Related

  1. median(double[] values)
  2. median(double[] x)
  3. median(double[] x)
  4. median(double[] x)
  5. median(double[][] values)
  6. median(final double... in)
  7. median(final double... values)
  8. median(final double[] values)
  9. median(final int[] values)