diff --git a/ArrayMax.java b/ArrayMax.java index cc16415..f0ccbfe 100644 --- a/ArrayMax.java +++ b/ArrayMax.java @@ -18,3 +18,34 @@ public static void main(String args[]){ System.out.println("Min is"+min); } } + + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class GFG { + + // function to find minimum value in an unsorted + // list in Java using Collection + public static Integer findMin(List 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 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); + } + +