In this tutorial, you will learn how to find the maximum and minimum value element from the ArrayList.
In this tutorial, you will learn how to find the maximum and minimum value element from the ArrayList.In this tutorial, you will learn how to find the maximum and minimum value element from the ArrayList. Java provides direct methods to get maximum and minimum value from any collection class i.e max() and min() respectively. Here is an example that consists of ArrayList of integers and using the max and min methods of Collections class, we have find the largest and smallest values from the list.
Example:
import java.util.*; class FindMaxMinUsingCollection { public static void main(String[] args){ ArrayListlist = new ArrayList (); list.add(50); list.add(15); list.add(450); list.add(550); list.add(200); Object minValue = Collections.min(list); Object maxValue = Collections.max(list); System.out.println("Minimum value is = " + minValue); System.out.println("Maximum value is = " + maxValue); } }
Output:
Minimum value is = 15 Maximum value is = 550