find minimum value in list java

Solutions on MaxInterview for find minimum value in list java by the best coders in the world

showing results for - "find minimum value in list java"
Jeanette
29 May 2018
1import java.util.ArrayList;
2import java.util.Collections;
3import java.util.List;
4
5public static Integer findMin(List<Integer> list)
6    {
7  
8        // check list is empty or not
9        if (list == null || list.size() == 0) {
10            return Integer.MAX_VALUE;
11        }
12  
13        // create a new list to avoid modification 
14        // in the original list
15        List<Integer> sortedlist = new ArrayList<>(list);
16  
17        // sort list in natural order
18        Collections.sort(sortedlist);
19  
20        // first element in the sorted list
21        // would be minimum
22        return sortedlist.get(0);
23    }