How to Get Main Element in an ArrayList in Java


In this example we will show the method to get the min element in an ArrayList in Java.

Source Code

package com.beginner.examples;

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

public class MinElementOfArrayList {

  public static void main(String[] args) {

    ArrayList arrays = new ArrayList();
    arrays.add(6);
    arrays.add(1);
    arrays.add(4);
    System.out.println("Min : " + Collections.min(arrays)); // get the min element
 }
}

Output:

Min : 1

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments