Find maximum element of Java ArrayList - Java Collection Framework

Java examples for Collection Framework:ArrayList

Description

Find maximum element of Java ArrayList

Demo Code

 
import java.util.ArrayList;
import java.util.Collections;
 
public class Main {
 
  public static void main(String[] args) {
   /*from  w  w w .ja v  a  2  s  .  co  m*/
    //create an ArrayList object
    ArrayList arrayList = new ArrayList();
   
    //Add elements to Arraylist
    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("1"));
    arrayList.add(new Integer("8"));
    arrayList.add(new Integer("3"));
    arrayList.add(new Integer("5"));
   
    Object obj = Collections.max(arrayList);
   
    System.out.println("Maximum Element of Java ArrayList is : " + obj);
  }
}

Result


Related Tutorials