How to Find Min Element of Java ArrayList


In this example, we may learn how to find the minimum element of ArrayList using min method of Collections class in Java.

Source Code

package com.beginner.examples;

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

public class FindMinimumOfArrayList {

	public static void main(String[] args) {
		//Create an array storage element.
		ArrayList arrayList = new ArrayList();
		
		arrayList.add(new Integer("603"));
		arrayList.add(new Integer("1024"));
		arrayList.add(new Integer("256"));
		arrayList.add(new Integer("4980"));
		
		//Use static Object min(Collection c) method of Collections class to find minimum element of  ArrayList.
		Integer result = Collections.min(arrayList);
		
		System.out.println("The Minimum Element of ArrayList is " + result);

	}

}

Output:

The Minimum Element ofArrayList is 256

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments