Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ArrayMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<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);
}