In Java, Math.min(a, b) returns the smaller of its two arguments. Math.min(3, 8) is 3.
Besides finding the lowest value, min is the standard way to set an upper limit: Math.min(100, level) never goes above 100.
A static method of the java.lang.Math class, available since the early versions of Java (JDK 1.0). Call it on the class name, as in Math.min(...). No import is needed, because classes in java.lang are always visible.
Syntax
Pass two numbers. Mixed types are widened to the larger type first.
Java
int low = Math.min(72, 95); // 72
double cheaper = Math.min(4.99, 3.49); // 3.49
int level = Math.min(100, battery + 30); // never above 100
int end = Math.min(start + 10, total); // last index of a page
Call
What it does
Math.min(4, 9)
int overload: 4.
Math.min(-5, 3L)
Mixed: -5 widens to long, result -5L.
Math.min(100, x)
Upper limit: x, but never more than 100.
Math.min(a, Math.min(b, c))
Smallest of three values.
min and max are mirror images. Together, Math.max(lo, Math.min(hi, v)) keeps v inside a range; Java 21 adds Math.clamp for that.
Library declarations
Java
// java.lang.Math
public static int min(int a, int b)
public static long min(long a, long b)
public static float min(float a, float b)
public static double min(double a, double b)
Parameters
Parameter
Description
a
The first value.
b
The second value.
Return Value
Return Value
Description
Same type as the (widened) arguments
The smaller of a and b. If they are equal, that value.