Java Array Max Value max(D... comparables)

Here you can find the source of max(D... comparables)

Description

Returns the maximum value.

License

Open Source License

Parameter

Parameter Description
D data type
comparables a parameter

Return

the maximum value

Declaration

static public <D extends Comparable<? super D>> D max(D... comparables) 

Method Source Code

//package com.java2s;
// Subject to BSD License. See "license.txt" distributed with this package.

public class Main {
    /**//from  ww w.j  a v a2s  . c  o  m
     * Returns the maximum value.
     * A <tt>null</tt> value isn't compared.
     * If the paramter list is empty, the result is <tt>null</tt>.
     * @param <D> data type
     * @param comparables
     * @return the maximum value
     */
    static public <D extends Comparable<? super D>> D max(D... comparables) {

        D max = null;

        for (int i = 0; i < comparables.length; i++) {
            D element = comparables[i];
            if (element != null) {
                if (max == null || max.compareTo(element) < 0) {
                    max = element;
                }
            }
        }

        return max;
    }
}

Related

  1. max(byte[] arr)
  2. max(byte[] array)
  3. max(byte[] array)
  4. max(byte[] lArray, byte[] rArray)
  5. max(byte[] values)
  6. max(double array[], int start, int length)
  7. max(double values[])
  8. max(double values[], int size)
  9. max(double... a)