From 64044e2125e4f85f923a9cb5d5d8b17110ed8108 Mon Sep 17 00:00:00 2001 From: Rahul1-2-3 <56497538+Rahul1-2-3@users.noreply.github.com> Date: Sun, 13 Oct 2019 10:34:45 +0530 Subject: [PATCH] Update ArrayMax.java --- ArrayMax.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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); + } + +