java arraylist integer min value
int minIndex = list.indexOf(Collections.min(list));
java arraylist integer min value
int minIndex = list.indexOf(Collections.min(list));
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);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us