Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ArrayMax.java #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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);
}