Java Array Max Value max(T... values)

Here you can find the source of max(T... values)

Description

max

License

Apache License

Declaration

@SafeVarargs
public static <T extends Comparable<? super T>> T max(T... values) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    @SafeVarargs
    public static <T extends Comparable<? super T>> T max(T... values) {
        T result = null;//w ww. j a  va 2  s  . c  om
        if (values != null) {
            for (T value : values) {
                if (compare(value, result, false) > 0) {
                    result = value;
                }
            }
        }
        return result;
    }

    public static <T extends Comparable<? super T>> int compare(T c1, T c2) {
        return compare(c1, c2, false);
    }

    public static <T extends Comparable<? super T>> int compare(T c1, T c2, boolean nullGreater) {
        if (c1 == c2) {
            return 0;
        } else if (c1 == null) {
            return nullGreater ? 1 : -1;
        } else if (c2 == null) {
            return nullGreater ? -1 : 1;
        }
        return c1.compareTo(c2);
    }
}

Related

  1. max(long[] array)
  2. max(Number... array)
  3. max(Number[] array)
  4. max(T first, T... others)
  5. max(T... elems)
  6. max(T[] args)
  7. max_array(byte[] arr)
  8. max_index(int[] v)
  9. max_of_ints(int[] data)