Home > coding, java > Find the maximum for an Iterable of Comparable

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;
    }
Advertisements
Categories: coding, java
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: