Getting the minimum element of the given collection, according to the natural ordering of its elements. All elements in the collection must implement the Comparable interface. Furthermore, all elements in the collection must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the collection).
package collection.demos;
import java.util.ArrayList;
import java.util.Collections;
public class FindMinInList {
public static void main(String[] args) {
ArrayList<Integer> numbers=new ArrayList<Integer>();
numbers.add(324233);
numbers.add(564534);
numbers.add(34534);
numbers.add(675666);
System.out.println("Minimum Integer : "+Collections.min(numbers));
}
}
package collection.demos;
import java.util.ArrayList;
import java.util.Collections;
public class FindMinInList {
public static void main(String[] args) {
ArrayList<Integer> numbers=new ArrayList<Integer>();
numbers.add(324233);
numbers.add(564534);
numbers.add(34534);
numbers.add(675666);
System.out.println("Minimum Integer : "+Collections.min(numbers));
}
}
Comments