Minimum and Maximum value from Integer List in Java

In this example, We will show you simple program about, How to find minimum and maximum value from Integer List in Java.

Example Program

package com.dineshkrish;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* 
* @author Dinesh Krishnan
*
*/
public class FindMinMax {
public static void main(String[] args) {
// defining list object
List<Integer> list = new ArrayList<Integer>();
// adding the elements to list
list.add(10);
list.add(100);
list.add(1000);
list.add(10000);
list.add(100000);
// getting minimum value from list
int minimumValue = Collections.min(list);
System.out.println("Minimum Value : "+minimumValue);
// getting maximum value from list
int maximumValue = Collections.max(list);
System.out.println("Maximum Value : "+maximumValue);
}
}

Output

Minimum Value : 10
Maximum Value : 100000

References

1. Java List Interface
2. Java ArrayList Class
3. Java Collections Class

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *