Java Number Min Value min(T a, T b)

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

Description

Compares two objects finding the minimum.

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 minimum of the two objects, null if both null

Declaration

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

Method Source Code

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

public class Main {
    /**/*w w w  .j  ava 2 s . co  m*/
     * Compares two objects finding the minimum.
     * 
     * @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 minimum of the two objects, null if both null
     */
    public static <T extends Comparable<? super T>> T min(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. min(String a, String b)
  2. min(String in, int len)
  3. min(String name)
  4. min(String s)
  5. min(T a, T b)
  6. min(T c1, T c2)
  7. min(T v1, T v2)
  8. min(T v1, T v2, int nullSupport)
  9. min2(double a, double b)