Here you can find the source of median(final ArrayList
Parameter | Description |
---|---|
values | sorted list of values. |
private static long median(final ArrayList<Long> values)
//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; } }