Java Integer min() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

Definition

In Java, Integer.min(a, b) returns the smaller of the two int values. If both are equal, it returns that value.

It matches Math.min(int, int), and it exists so you can write Integer::min as a method reference when combining numbers in a stream.

A static method of java.lang.Integer (since Java 8): call it on the class, as Integer.min(...). Integer lives in java.lang, so no import is needed. Integer.min() was added in Java 8.

Syntax

Pass the two numbers to compare.

Java
int a = Integer.min(3, 9);     // 3
int b = Integer.min(-5, -2);    // -5
int c = Integer.min(7, 7);      // 7
CallWhat it does
Integer.min(a, b)The smaller of a and b.
Math.min(a, b)Same result for int; also has other numeric versions.
stream.reduce(Integer::min)Finds the smallest value in a stream of numbers.
Integer.min(limit, value)Caps a value so it never goes above limit.

Use min for upper limits and max for lower limits. Combine them to keep a value inside a range.

Library declarations
Java
// java.lang.Integer
public static int min(int a, int b)

Parameters

ParameterDescription
a (int)The first number.
b (int)The second number.

Return Value

Return ValueDescription
intThe smaller of a and b.

Compare with Similar Methods

Related methods:

MethodHow it differs
max(a, b)The larger of two values instead.
sum(a, b)Another Java 8 method meant for reduce.
signum(i)Tells you only whether a number is negative, zero, or positive.
Collections.min()The smallest element of a whole collection.

Java Examples

Example 1 — Pick the Smaller Number

Call min on pairs of numbers, including negative values and the extremes of int.

Java
public class IntegerMinDemo {
    public static void main(String[] args) {
        System.out.println("min(3, 9):        " + Integer.min(3, 9));
        System.out.println("min(9, 3):        " + Integer.min(9, 3));
        System.out.println("min(-5, -2):      " + Integer.min(-5, -2));
        System.out.println("min(7, 7):        " + Integer.min(7, 7));
        System.out.println("min(MIN, MAX):    " + Integer.min(Integer.MIN_VALUE, Integer.MAX_VALUE));
    }
}

How It Works

  1. Order does not matter. min(3, 9) and min(9, 3) both return 3.
  2. Negative numbers. -5 is smaller than -2, because it is further from zero.
  3. Equal inputs. min(7, 7) returns 7, so a tie is not a problem.
  4. The extremes. Comparing the smallest and largest possible int returns the smaller one, Integer.MIN_VALUE.

Example 2 — Find the Lowest Price with Integer::min

Use Integer::min as a method reference to reduce an array of prices to the cheapest one.

Java
import java.util.Arrays;

public class IntegerMinReduce {
    public static void main(String[] args) {
        int[] prices = {450, 399, 520, 405, 399};

        int cheapest = Arrays.stream(prices).reduce(Integer.MAX_VALUE, Integer::min);
        System.out.println("cheapest price: " + cheapest);

        int manual = Integer.MAX_VALUE;
        for (int price : prices) {
            manual = Integer.min(manual, price);
        }
        System.out.println("with a loop:    " + manual);
    }
}

How It Works

  1. A safe starting point. Integer.MAX_VALUE is bigger than any price, so the first real price always replaces it.
  2. reduce combines pairs. The stream feeds the current cheapest price and the next price to Integer::min.
  3. The same idea in a loop. The loop keeps the smaller of the current best and each price.
  4. Same answer. Both end with 399, even though that price appears twice.

Example 3 — Cap a Discount and Clamp a Percentage

Use min to set an upper limit, then combine it with max to keep a value inside a range.

Java
public class IntegerMinCap {
    static int cappedDiscount(int requested) {
        return Integer.min(requested, 50);
    }

    static int clamp(int value, int low, int high) {
        return Integer.max(low, Integer.min(value, high));
    }

    public static void main(String[] args) {
        System.out.println("discount 20%: " + cappedDiscount(20));
        System.out.println("discount 80%: " + cappedDiscount(80));

        System.out.println("clamp(150): " + clamp(150, 0, 100));
        System.out.println("clamp(-20): " + clamp(-20, 0, 100));
        System.out.println("clamp(55):  " + clamp(55, 0, 100));
    }
}

How It Works

  1. Upper limit with min. A requested 80% discount is cut down to 50, while 20% is already below the cap and stays as it is.
  2. Clamp in two steps. min(value, high) caps the top, then max(low, ...) raises the bottom.
  3. Too big. 150 is capped to 100 by the inner min.
  4. Too small and just right. -20 is lifted to 0 by the outer max, and 55 passes through both unchanged.

Frequently Asked Questions

It returns the smaller of two int values. Integer.min(3, 9) returns 3.
For two ints they give the same result. Integer.min was added in Java 8 mainly so Integer::min can be used as a method reference.
Use Arrays.stream(array).min().getAsInt(), or reduce(Integer.MAX_VALUE, Integer::min), or a simple loop.
Combine both methods: Integer.max(low, Integer.min(value, high)). The inner min sets the upper limit and the outer max sets the lower limit.
Java 8. In older versions use Math.min(a, b).

Next: numberOfLeadingZeros()

Count the zero bits before the first 1 bit.

numberOfLeadingZeros() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful