Java Number Max Value max(T a, T b)

Here you can find the source of max(T a, T b)

Description

Compares two objects finding the maximum.

License

Apache License

Parameter

Parameter Description
T the object type
a item that compareTo is called on, may be null
b item that is being compared, may be null

Return

the maximum of the two objects, null if both null

Declaration

public static <T extends Comparable<? super T>> T max(T a, T b) 

Method Source Code

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

public class Main {
    /**//from w  w  w .  j a  v  a 2  s  .c  om
     * Compares two objects finding the maximum.
     * 
     * @param <T>  the object type
     * @param a  item that compareTo is called on, may be null
     * @param b  item that is being compared, may be null
     * @return the maximum of the two objects, null if both null
     */
    public static <T extends Comparable<? super T>> T max(T a, T b) {
        if (a != null && b != null) {
            return a.compareTo(b) >= 0 ? a : b;
        }
        if (a == null) {
            if (b == null) {
                return null;
            } else {
                return b;
            }
        } else {
            return a;
        }
    }
}

Related

  1. max(String content, int max, String dotDotDot)
  2. max(String left, String right)
  3. max(String name)
  4. max(String s)
  5. max(T a, T b)
  6. max(T c1, T c2)
  7. max(T c1, T c2)
  8. max(T v1, T v2)
  9. max(T v1, T v2, int nullSupport)