How to get min element from the given list?

The java.util.Collections class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection, and a few other odds and ends.

Collections.min() method will returns the minimum element of the given collection, according to the natural ordering of its elements Syntax: public static int min(Collection coll)

Example

package com.w3spoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
public class Test {
 
    public static void main(String a[]){         
        List<Integer> list = new ArrayList<Integer>();
        list.add(32);
        list.add(61);
        list.add(73);
        list.add(10);
        list.add(9);
        list.add(86);
        System.out.println("Minimum element from the list: "+Collections.min(list));
    }
}

Output

Minimum element from the list: 9

Java Collections class examples

Please follow and like us:
Content Protection by DMCA.com