Close

Java Collections - Collections.min() Examples

Java Collections Java Java API 


Class:

java.util.Collections

java.lang.Objectjava.lang.Objectjava.util.Collectionsjava.util.CollectionsLogicBig

Methods:

public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)

Returns the minimum element of the given collection, according to the natural ordering of its elements.



public static <T> T min(Collection<? extends T> coll,
                        Comparator<? super T> comp)

Returns the minimum element of the given collection, according to the order induced by the specified comparator.


Examples


package com.logicbig.example.collections;

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

public class MinExample {

public static void main(String... args) {
List<Integer> list = Arrays.asList(20, 10, 100, 140);
Integer min = Collections.min(list);
System.out.println(min);
}
}

Output

10




package com.logicbig.example.collections;

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

public class MinExample2 {

public static void main(String... args) {
List<Integer> list = Arrays.asList(20, 10, 100, 140);
Integer min = Collections.min(list, Collections.reverseOrder());
System.out.println(min);
}
}

Output

140




See Also