To find out maximum number from a list of an array?

To find out maximum number from a list of an array?

Previous Home Next

 

In this program we will understand how to find out the maximum element of Arraylist using Maxmethod of  collection class.

Max method of collection is used here to find out the maximum element of an array.
 static object max collection(c) method of collection class.
This method returns the maximum element of arraylist .it returns the value according to natural ordering.

to get maximum element of arraylist first define the arrylist and then using the max method colletion class
maximum element will come out.

 


import java.util.ArrayList;
import java.util.Collections;

public class MaximumfArrayListExample
{
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();

arrayList.add(new Integer("6594"));
arrayList.add(new Integer("2534"));
arrayList.add(new Integer("1253");
arrayList.add(new Integer("5698"));
arrayList.add(new Integer("5093"));

Object obj = Collections.max(arrayList);

System.out.println(" The Maximum Element of Java ArrayList is : " + obj);

}

}



The maximum element of Java ArrayList is : 6594
Previous Home Next