Java ProgramsCollectionsCollection Minimum

Collection Minimum in Java

beginner·  Collections  ·  Collections Utility

Problem

The Collections utility class provides static helper methods that operate on any List — Collections.min() scans one and returns whichever element is smallest, without the caller writing a comparison loop.

Given a List of integers in no particular order, find the smallest one.

Input
[78, 45, 92, 33, 61]
Output
Minimum: 33

Java Program

Java
import java.util.Arrays; import java.util.Collections; import java.util.List; public class CollectionMinimum { public static void main(String[] args) { List<Integer> scores = Arrays.asList(78, 45, 92, 33, 61); int lowest = Collections.min(scores); // single pass, returns the smallest element found System.out.println("Minimum: " + lowest); } }

Output

Minimum: 33

Core Logic

Handing the whole List to Collections.min() lets the utility method do the scanning internally, instead of tracking a running minimum by hand.

How It Works
  1. 1Arrays.asList(78, 45, 92, 33, 61) builds a fixed-size List&lt;Integer&gt; from the given values.
  2. 2Collections.min(scores) walks the whole list once, comparing each element using its natural ordering, and returns the smallest one found.
  3. 3For Integer elements, natural ordering is just numeric order, the same comparison &lt; would use.
  4. 4No sorting happens — min() only needs a single pass to find the smallest value, not a fully ordered list.
Scanning [78, 45, 92, 33, 61], 33 is the smallest value found, so Collections.min() returns it.
💡

Key Point: Collections.min() works on any List whose elements implement Comparable — swap in Strings or any other Comparable type and the exact same call still finds the smallest one.

Complexity
Time Complexity: O(n)Space Complexity: O(1)

Why: Collections.min() makes a single linear pass over the list, comparing each element against the running minimum found so far, with no extra storage beyond that one tracked value.

Key Concepts

Collections.min()Listutility method

Approach 2: Java 8

Java
import java.util.Arrays; import java.util.List; public class CollectionMinimumStream { public static void main(String[] args) { List<Integer> scores = Arrays.asList(78, 45, 92, 33, 61); // Reduces the stream to its smallest element, wrapped in an Optional int lowest = scores.stream().min(Integer::compareTo).get(); System.out.println("Minimum: " + lowest); } }

Output

Minimum: 33

Core Logic

A stream's min() terminal operation mirrors max() — it reduces the whole stream down to its smallest element in one call.

How It Works
  1. 1scores.stream() opens a stream over the list's elements.
  2. 2.min(Integer::compareTo) reduces the stream to the single smallest element, using the method reference as the comparison rule.
  3. 3.min() also returns an Optional&lt;Integer&gt;, so .get() unwraps it — safe here since scores is known to be non-empty.
  4. 4The comparison logic is identical to max()'s, just interpreting the result the other way.
Streaming [78, 45, 92, 33, 61] through min() reduces to 33, the same result Collections.min() finds.
💡

Key Point: Swapping max() for min() is the entire difference from the maximum version — everything else about the stream pipeline stays the same.

Complexity
Time Complexity: O(n)Space Complexity: O(1)

Why: min() still performs a single linear scan internally, comparing each element against the running minimum, without collecting anything.

Key Concepts

Streammin()method reference

Related Programs