Here you can find the source of getMedian(List
Parameter | Description |
---|---|
numbers | List<Double> containing the list of numbers |
private static Double getMedian(List<Double> numbers)
//package com.java2s; //License from project: Open Source License import java.util.Collections; import java.util.List; public class Main { /** /*from w ww . j a va 2 s.c o m*/ * Given a list of numbers returns the median of the of the list * @param numbers List<Double> containing the list of numbers * @return Double containing the median of the list of numbers */ private static Double getMedian(List<Double> numbers) { double median; Collections.sort(numbers); int size = numbers.size(); if (size % 2 != 0) { median = numbers.get(size / 2); } else { if (size != 1) { median = (numbers.get(size / 2) + numbers.get((size / 2) - 1)) / 2.0; } else { median = numbers.get(size / 2); } } return median; } }