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
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)); ... The min() method returns the number with the lowest value from a pair 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.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_math.asp
Java Math
How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ library โ€บ math โ€บ min
Java Math min()
Here, min() is a static method. Hence, we are accessing the method using the class name, Math. The min() method takes two parameters. arg1/arg2 - arguments among which smaller value is returned ยท Note: The data types of the arguments should be either int, long, float, or double.
๐ŸŒ
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.
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ tryjava.asp
W3Schools online JAVA editor
The W3Schools online code editor allows you to edit code and view the result in your browser
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! :)

๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ java-min-function
Java min Function
March 22, 2025 - Next, We used the Function on variables g, h, i, and j (they belong to float type). The next three System.out.println statements will call the float type method ( static float min(float a, float b) ) and find the smallest among the values. Last, We used this Math function on variables k, l, m, and n (they belong to the long type).
Find elsewhere
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ java โ€บ number_min.htm
Java - min() Method
Java Vs. C++ ... The method gives the smaller of the two arguments. The argument can be int, float, long, double. ... double min(double arg1, double arg2) float min(float arg1, float arg2) int min(int arg1, int arg2) long min(long arg1, long ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_ref_math.asp
Java Math Reference
How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_math_max.asp
Java Math max() Method
Java Examples Java Videos Java ... number with the highest value from a pair of numbers. Tip: Use the min() method to return the number with the lowest value....
๐ŸŒ
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!
๐ŸŒ
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.
๐ŸŒ
Java Tutorial HQ
javatutorialhq.com โ€บ java tutorial โ€บ java.lang โ€บ math โ€บ min() method example
Java Math min() method example
September 30, 2019 - On this document we will be showing a java example on how to use the min() method of Math Class. The max() returns which of the two method argument has the lowest value numerically. This method is overloaded such that it handles all primitive data type. Here are the overloaded methods: ... The overloaded methods are basically the same, itโ€™s just that they deal with different data type either int, long, float, and double
๐ŸŒ
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[]) { float f1 = -2.225f; float f2 = -6.5f; //This will print the smaller float number System.out.println(Math.min(f1, f2)); double d1 = 40000; double d2 = 41000; //This will print the smaller double number System.out.println(Math.min(d1, d2)); } } ... public static int min(int a, int b): Compares the passed integer numbers and returns the smaller integer number.
๐ŸŒ
JavaBeat
javabeat.net โ€บ home โ€บ how to use math.min() method in java?
How to Use Math.min() Method in Java?
January 20, 2026 - To use the โ€œMath.min()โ€ method in Java, pass two variables from which the minimum value needs to be found as arguments and the method returns the smallest value argument. If one of the operand values is negative, then the negative value ...
๐ŸŒ
javaspring
javaspring.net โ€บ blog โ€บ mathmin-java
Mastering `Math.min()` in Java: A Comprehensive Guide โ€” javaspring.net
July 13, 2021 - One of the most commonly used methods in this class is `Math.min()`. This method allows developers to easily find the minimum value between two numbers. Whether you're working on a simple ...