Java Collection Median median00(Collection coll)

Here you can find the source of median00(Collection coll)

Description

median

License

Open Source License

Declaration

public static <T extends Comparable<? super T>> T median00(Collection<T> coll) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Main {
    public static <T extends Comparable<? super T>> T median00(Collection<T> coll) {
        if (coll.isEmpty()) {
            return null;
        } else {/*from  w w w.ja v a  2  s. c  o m*/
            List<T> copy = new ArrayList<T>(coll);
            Collections.sort(copy);
            int index = (copy.size() - 1) / 2;
            return copy.get(index);
        }
    }
}

Related

  1. median(Collection values)