This post will discuss how to find the minimum and maximum value in an unsorted list of integers in Java without using Java 8 Stream.

1. Naive solution

Here’s a naive (but efficient) way of finding find minimum and maximum value in an unsorted list, where we check against all values present in the list and maintain the minimum and maximum value found so far.

Min


Download  Run Code

Max


Download  Run Code

2. Using Collections.max() method

Collections.min() method returns the minimum element in the specified collection, and Collections.max() returns the maximum element in the specified collection, according to the natural ordering of its elements.

Min


Max



 
Both these methods iterate over the entire list. Hence, they require time proportional to the size of the list.

3. Using Sorting

This is the least efficient approach but will get the work done. The idea is to sort the list in the natural order, and then the first or last element would be the minimum and maximum element, respectively. Following’s implementation in Java:

Min


Download  Run Code

Max


Download  Run Code

That’s all about finding the min and max values in an unsorted Integer List in Java.