Java Collections min() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.util.Collections

Definition

In Java, Collections.min(coll) returns the smallest element of a collection according to natural order. Like max, it scans the elements once, accepts any Collection, and does not change it.

Collections.min(coll, comparator) uses your own definition of "smallest", such as the shortest name or the entry with the lowest value.

A static method of the java.util.Collections utility class, available since Java 1.2. Call it on the class name, as in Collections.min(...), after import java.util.Collections;. You never create a Collections object.

Syntax

Pass a non-empty collection, and optionally a Comparator.

Java
List<Double> prices = Arrays.asList(19.99, 4.5, 12.0);
double cheapest = Collections.min(prices);                              // 4.5
String shortest = Collections.min(names, Comparator.comparingInt(String::length));
CallWhat it does
Collections.min(coll)Smallest element in natural order.
Collections.min(coll, cmp)Smallest element according to cmp.
Collections.min(map.values())Lowest value in a map.
Collections.min(coll, String.CASE_INSENSITIVE_ORDER)Alphabetically first string, ignoring case.

Natural order for strings is by character code, so every uppercase letter is "smaller" than every lowercase letter. ISO dates written as yyyy-MM-dd strings compare correctly as text, which makes min a quick way to find the earliest one.

Library declarations
Java
// java.util.Collections
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp)

Parameters

ParameterDescription
collThe collection to examine. Must not be empty.
compThe comparator that defines the order. null means natural order.

Return Value

Return ValueDescription
TThe smallest element of the collection.

Compare with Similar Methods

Related ways to find extreme values:

MethodHow it differs
max(coll)The largest element instead.
treeSet.first()Constant-time minimum for a TreeSet.
sort(list)Orders everything; list.get(0) is then the minimum.
binarySearchFinds a specific value in sorted data.

Java Examples

Example 1 — Cheapest Price and Earliest Date

Find the minimum of a list of prices and of ISO date strings.

Java
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class CollectionsMinBasic {
    public static void main(String[] args) {
        List<Double> prices = Arrays.asList(19.99, 4.5, 12.0);
        System.out.println("Cheapest: " + Collections.min(prices));

        List<String> dates = Arrays.asList("2024-03-15", "2023-12-01", "2024-01-20");
        System.out.println("Earliest: " + Collections.min(dates));
    }
}

How It Works

  1. Numbers. Among 19.99, 4.5, and 12.0, the natural order of Double picks 4.5.
  2. Dates as text. In yyyy-MM-dd form, comparing strings character by character compares year, then month, then day.
  3. Earliest wins. "2023" is smaller than "2024", so 2023-12-01 is the minimum without parsing any date.

Example 2 — Case-Insensitive and Shortest-Word Minimums

Compare natural order with a case-insensitive comparator, then find the shortest name.

Java
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionsMinComparator {
    public static void main(String[] args) {
        List<String> fruit = Arrays.asList("banana", "apple", "Cherry");
        System.out.println("Natural:          " + Collections.min(fruit));
        System.out.println("Case-insensitive: " + Collections.min(fruit, String.CASE_INSENSITIVE_ORDER));

        List<String> names = Arrays.asList("Christopher", "Al", "Bea");
        System.out.println("Shortest name:    " + Collections.min(names, Comparator.comparingInt(String::length)));
    }
}

How It Works

  1. Capital C wins in natural order. 'C' has code 67, smaller than 'a' (97) and 'b' (98), so "Cherry" comes first.
  2. Ignoring case. With CASE_INSENSITIVE_ORDER, "apple" sorts before "banana" and "cherry", so it is the minimum.
  3. By length. Comparator.comparingInt(String::length) compares lengths 11, 2, and 3, so "Al" is returned.

Example 3 — Lowest Stock Level in a Map

Get the smallest value in a map, and the key that belongs to it.

Java
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public class CollectionsMinMap {
    public static void main(String[] args) {
        Map<String, Integer> stock = new LinkedHashMap<>();
        stock.put("apples", 12);
        stock.put("pears", 3);
        stock.put("plums", 5);

        System.out.println("Lowest count: " + Collections.min(stock.values()));

        Map.Entry<String, Integer> low = Collections.min(stock.entrySet(), Map.Entry.comparingByValue());
        System.out.println("Reorder: " + low.getKey() + " (" + low.getValue() + " left)");
    }
}

How It Works

  1. Values are a collection. stock.values() is a Collection<Integer>, so min returns 3 directly.
  2. Keep the key. To know which fruit is low, search the entry set instead of the values.
  3. Compare entries by value. Map.Entry.comparingByValue() (Java 8) orders entries by their counts, so the pears entry is the minimum.

Frequently Asked Questions

The smallest element of the collection, using natural order or the given comparator.
min throws NoSuchElementException.
Natural String order compares character codes, and all uppercase letters have smaller codes than lowercase letters. Use String.CASE_INSENSITIVE_ORDER to ignore case.
Collections.min(map.entrySet(), Map.Entry.comparingByValue()).getKey().
Yes. It needs one pass over the elements, while sorting needs about n log n comparisons.

Next: nCopies()

Create an immutable list holding n copies of one value.

nCopies() 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.

11 people found this page helpful