Answers for "find minimum value in list java"

0

find minimum value in list java

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public static Integer findMin(List<Integer> list)
    {
  
        // check list is empty or not
        if (list == null || list.size() == 0) {
            return Integer.MAX_VALUE;
        }
  
        // create a new list to avoid modification 
        // in the original list
        List<Integer> sortedlist = new ArrayList<>(list);
  
        // sort list in natural order
        Collections.sort(sortedlist);
  
        // first element in the sorted list
        // would be minimum
        return sortedlist.get(0);
    }
Posted by: Guest on June-17-2021

Code answers related to "find minimum value in list java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language