
how to find maximum and minimum from a list using max & min method of collection class

Here is an example of ArrayList which finds 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.
import java.util.*;
class FindMaxMinUsingCollection
{
public static void main(String[] args){
ArrayList<Integer> list = new ArrayList<Integer>();
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);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.