Find the maximum for an Iterable of Comparable

    public static <T extends Comparable<T>> T getMaximum(Iterable<T> values) {
        
        T max = null;

        for (T value : values) {
            if (max == null || max.compareTo(value) < 0) {
                max = value;
            }
        }
        return max;
    }

Leave a comment