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
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-min-method-examples
Java Math min() method with Examples - GeeksforGeeks
January 9, 2026 - 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()
Initially, the variable min stores the first element of the array. Here, we have used the for loop to access all elements of the array. Notice the line, min = Math.min(min, arr[i]) The Math.min() method compares the variable min with all elements of the array and assigns the minimum value to min.
🌐
W3Schools
w3schools.com › java › ref_math_min.asp
Java Math min() Method
Java Examples Java Videos Java ... ... System.out.println(Math.min(2.0, 0.25)); System.out.println(Math.min(31.2f, 18.0f)); System.out.println(Math.min(14, 22)); System.out.println(Math.min(96L, 2048L));...
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 › home › java/lang › java math min method
Java Math Min Method
September 1, 2008 - 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.
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Math › min
Java Math min() - Get Minimum Value | Vultr Docs
September 27, 2024 - Here, Math.min() is used to compare x and y. The function correctly identifies 3.28 as the smaller value. Include negative floating-point numbers in your example.
🌐
iO Flood
ioflood.com › blog › math-min-java
Using Math.min in Java: A Detailed Tutorial
February 29, 2024 - When using Math.min(), it’s crucial to ensure that both arguments are of the same data type. If they’re not, Java will automatically convert the smaller data type to the larger one, which can lead to unexpected results. For example, if one argument is an ‘int’ and the other is a ‘double’, the ‘int’ will be converted to a ‘double’ before the comparison is made.
🌐
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! ... Learn to code in Java — a robust programming language used to create software, ...
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_long.htm
Java - Math min(long x, long y) Method
package com.tutorialspoint; public ... long y = 497; // call min and print the result System.out.println("Math.min(" + x + "," + y + ")=" + Math.min(x, y)); } } Let us compile and run the above program, this will produce the following ...
🌐
Tutorial Gateway
tutorialgateway.org › java-min-function
Java min Function
March 22, 2025 - In this example, we use the Math.min function to find the Minimum or Smaller value from a different set of data types and display the output. First, we used it directly on both positive and negative integer values. The first three statements will call the integer type static int min(integer a, integer b) method and find the smallest among the values. Next, We used the Java Math.min Function on variables b, c, d, and e (they belong to double type).
🌐
Javatpoint
javatpoint.com › java-math-min-method
Java Math.min() method with Examples - Javatpoint
Java CopyOnWriteArrayList · indexOf() lastIndexOf() clone() toArray() Math.abs() Math.max() Math.min() Math.round() Math.sqrt() Math.cbrt() Math.pow() Math.signum() Math.ceil() Math.copySign() Math.nextAfter() Math.nextUp() Math.nextDown() Math.floor() Math.floorDiv() Math.random() Math.rint() Math.hypot() Math.ulp() Math.getExponent() Math.IEEEremainder() Math.addExact() Math.subtractExact() Math.multiplyExact() Math.incrementExact() Math.decrementExact() Math.negateExact() Math.toIntExact() Math.log() Math.log10() Math.log1p() Math.exp() Math.expm1() Math.sin() Math.cos() Math.tan() Math.asin() Math.acos() Math.atan() Math.sinh() Math.cosh() Math.tanh() Math.toDegrees ·
🌐
TutorialKart
tutorialkart.com › java › java-math › java-math-min
Java Math.min() - Minimum Value
November 23, 2020 - Java Program · </> Copy · public class MathExample { public static void main(String[] args) { int a = 10; int b = 5; int result = Math.min(a, b); System.out.println(result); } } Output ·
🌐
Scaler
scaler.com › home › topics › min() in java
min() in Java - Scaler Topics
April 8, 2024 - Find the minimum of two float type positive numbers: In the following example, we use will pass two numbers (of type float) as arguments to min() method and find the smallest of the two float numbers.
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › math › min() method example
Java Math min() method example
September 30, 2019 - package com.javatutorialhq.jav...seInt(value1); int b = Integer.parseInt(value2); // get the result of min method int result = Math.min(a,b); System.out.print("Lowest value:"+result); } }...
🌐
CodeGym
codegym.cc › java blog › java math › java math.min() method
Java Math.min() method
September 28, 2023 - package com.math.min.core public class MathMinMethod { public static void main(String[] args) { int leenasAge = 10; int tiffanysAge = 15; // example of min () function int min = Math.min(leenasAge, tiffanysAge); System.out.print("Who's the younger ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_double.htm
Java - Math min(double x, double y) Method
package com.tutorialspoint; public ... y = 497.99; // call min and print the result System.out.println("Math.min(" + x + "," + y + ")=" + Math.min(x, y)); } } Let us compile and run the above program, this will produce the following ...
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-math-min-method
Java Math.min() Method
For example: -7 and -3, the min number is -7. 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)); } } Output: public ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_float.htm
Java - Math min(float x, float y) Method
package com.tutorialspoint; public class MathDemo { public static void main(String[] args) { // get two float numbers float x = 60984.1f; float y = 497.99f; // call min and print the result System.out.println("Math.min(" + x + "," + y + ")=" + Math.min(x, y)); } } Let us compile and run the ...
🌐
JavaBeat
javabeat.net › home › how to use math.min() method in java?
How to Use Math.min() Method in Java?
November 30, 2023 - Inside the main “public” type class “javabeat”, two “int” type variables are declared and initialized with dummy positive values. Then, both of these variables are passed as arguments for the “Math.min()” method. This function returns the argument having the minimum value.