Minimum number from the list of an array ?
Previous | Home | Next |
This example shows how to find out the minimum element of array list using min method of collection class.
To find out the minimum element of Java ArrayList use,
use static Object min(Collection c) method of Collections class.
Min method of collection class returns the minimum element of Java ArrayList according to
its natural ordering.
Create an ArrayList object.
Add elements to Arraylist
create object of method asObject obj = Collections.min(arrayList);
import java.util.ArrayList;
import java.util.Collections;
public class MinimumArrayListExample {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add(new Integer("2356"));
arrayList.add(new Integer("5694"));
arrayList.add(new Integer("1025"));
arrayList.add(new Integer("3241"));
arrayList.add(new Integer("8924"));
Object obj = Collections.min(arrayList);
System.out.println("The Minimum Element of Java ArrayList is : " + obj);
}
}
The minimum Element of java ArrayList is : 1025
Previous | Home | Next |