java max array
public static String max(String[] arr) {
String result = arr[0];
for (int i = 1; i < arr.length; ++i) {
if (result.compareTo(arr[i]) < 0) result = arr[i];
}
return result;
}
java max array
public static String max(String[] arr) {
String result = arr[0];
for (int i = 1; i < arr.length; ++i) {
if (result.compareTo(arr[i]) < 0) result = arr[i];
}
return result;
}
max array number in java
Integer[] num = { 2, 4, 7, 5, 9 };
// using Collections.min() to find minimum element
// using only 1 line.
int min1 = Collections.min(Arrays.asList(num));
// using Collections.max() to find maximum element
// using only 1 line.
int max1 = Collections.max(Arrays.asList(num));
System.out.println(min1); // 2
System.out.println(max1); // 9
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