int

public static int min(int a, int b) {
    return (a <= b) ? a : b;
}

long

public static long min(long a, long b) {
     return (a <= b) ? a : b;
}

float

public static float min(float a, float b) {
    if (a != a) return a;   // a is NaN
    if ((a == 0.0f) && (b == 0.0f) && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
         return b;
    }
    return (a <= b) ? a : b;
 }

double

public static double min(double a, double b) {
    if (a != a) return a;   // a is NaN
    if ((a == 0.0d) && (b == 0.0d) && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
        return b;
    }
    return (a <= b) ? a : b;
}

More info: Here

Answer from Gray on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_math_min.asp
Java Math min() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate · ❮ Math Methods · Get the lowest value from different pairs of numbers: ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-min-method-examples
Java Math min() method with Examples - GeeksforGeeks
January 9, 2026 - Explanation: The method compares a positive and a negative integer. Negative numbers are always smaller than positive numbers. Therefore, -23 is returned as the minimum value. Math.min() compares two negative values.
🌐
Programiz
programiz.com › java-programming › library › math › min
Java Math min()
Become a certified Java programmer. Try Programiz PRO! ... The min() method returns the smaller value among the specified arguments. class Main { public static void main(String[] args) { // returns minimum of 25 and 31 System.out.println(Math.min(25, 31)); } } // Output: 25
Top answer
1 of 6
22

int

public static int min(int a, int b) {
    return (a <= b) ? a : b;
}

long

public static long min(long a, long b) {
     return (a <= b) ? a : b;
}

float

public static float min(float a, float b) {
    if (a != a) return a;   // a is NaN
    if ((a == 0.0f) && (b == 0.0f) && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
         return b;
    }
    return (a <= b) ? a : b;
 }

double

public static double min(double a, double b) {
    if (a != a) return a;   // a is NaN
    if ((a == 0.0d) && (b == 0.0d) && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
        return b;
    }
    return (a <= b) ? a : b;
}

More info: Here

2 of 6
10

Java 7 documentation:

Returns the smaller of two int values. That is, the result the argument closer to the value of Integer.MIN_VALUE. If the arguments have the same value, the result is that same value.

Behaviour:

Math.min(1, 2) => 1
Math.min(1F, 2) => 1F
Math.min(3D, 2F) => 2D
Math.min(-0F, 0F) => -0F
Math.min(0D, -0D) => -0D
Math.min(Float.NaN, -2) => Float.NaN
Math.min(-2F, Double.NaN) => Double.NaN

java.lang.Math and java.lang.StrictMath Source:

public static int min(int a, int b) {
    return (a <= b) ? a : b;
}

java.lang.Math Bytecode (javap -c Math.class of Oracle's JDK's JRE's rt.jar):

public static int min(int, int);
Code:
   0: iload_0           // loads a onto the stack
   1: iload_1           // loads b onto the stack
   2: if_icmpgt     9   // pops two ints (a, b) from the stack
                        // and compares them
                        // if b>a, the jvm continues at label 9
                        // else, at the next instruction, 5
                        // icmpgt is for integer-compare-greater-than
   5: iload_0           // loads a onto the stack
   6: goto          10  // jumps to label 10
   9: iload_1           // loads 
  10: ireturn           // returns the currently loaded integer

If the comparison at 5 is true, a will be loaded, the jvm will jump to 10 and return a, if the comparison yields false, it will jump to 9, which will load and return b.

Intrinsics:

This .hpp file of the Java 8 Hotspot JVM hints that it optimizes Math.min even further with optimized machine code:

do_intrinsic(_min, java_lang_Math, min_name, int2_int_signature, F_S)

This means the above bytecode won't be executed by the Java 8 Hotspot JVM. However, this differs from JVM to JVM, which is why I also explained the bytecode!

Hopefully, now you know all there is to know about Math.min! :)

🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_int.htm
Java - Math min(int x, int y) Method
The Java Math min(int a, int b) returns the smaller of two int values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
5 days ago - Returns the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the Integer.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to the Integer.MIN_VALUE.
🌐
CodeGym
codegym.cc › java blog › java math › java math.min() method
Java Math.min() method
September 28, 2023 - Java provides a system library known as “java.lang.Math” for extensive handy operations. From trigonometry to logarithmic functions, you can find min/max or even absolute of a number using the methods provided by this library due to its diverse functionalities. Here’s a regular representation of the method. Math.min(a, b) Kindly note that this function accepts two parameters of same types int, long, float or double.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › java › math methods › .min()
Java | Math Methods | .min() | Codecademy
October 22, 2022 - The Math.min() method returns the minimum value from the given two arguments. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › min
Java Math min() - Get Minimum Value
September 27, 2024 - The Math.min() function in Java serves as a simple yet powerful tool for determining the minimum value between two inputs. Whether dealing with integers, floating points, handling negative values, or involved in more complex expressions, this ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_long.htm
Java - Math min(long x, long y) Method
The Java Math min(long a, long b) returns the smaller of two long values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.
🌐
iO Flood
ioflood.com › blog › math-min-java
Using Math.min in Java: A Detailed Tutorial
February 29, 2024 - The Math.min() function in Java is a simple yet powerful tool that can save you a lot of time and effort when dealing with numerical comparisons. The function takes two arguments and returns the smaller of the two.
🌐
Scaler
scaler.com › home › topics › min() in java
min() in Java - Scaler Topics
April 8, 2024 - The Math.min() is a built-in method in Java that which accepts two parameters and returns the minimum of the two.
🌐
Tutorial Gateway
tutorialgateway.org › java-min-function
Java min Function
March 22, 2025 - Java Programming provides four different min functions to find the Minimum or Smaller value from the given two arguments. The following function will accept positive or negative integer value as the first and second argument and returns the ...
🌐
TutorialKart
tutorialkart.com › java › java-math › java-math-min
Java Math.min() - Minimum Value
November 23, 2020 - Math toRadians · Advanced · Java Date & Time · Java MySQL · min() accepts two numbers as arguments, and returns the smaller of the two values. Following is the syntax of min() method.
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-min-method
Java Math.min() Method
October 9, 2022 - public class JavaExample { public static void main(String args[]) { int a = 10, b = 20; int x = -10, y = -20; System.out.println("Minimum of a and b: "+Math.min(a,b)); System.out.println("Minimum of x and y: "+Math.min(x,y)); } }
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_float.htm
Java - Math min(float x, float y) Method
The Java Math min(float a, float b) returns the smaller of two float values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_double.htm
Java - Math min(double x, double y) Method
The Java Math min(double a, double b) returns the smaller of two double values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.