max array number in java code example
Example 1: max in array java
Integer[] num = { 2, 4, 7, 5, 9 };
int min = Collections.min(Arrays.asList(num));
int max = Collections.max(Arrays.asList(num));
Example 2: how to get the max value of an array java
public static double arrayMax(double[] arr) {
double max = Double.NEGATIVE_INFINITY;
for(double cur: arr)
max = Math.max(max, cur);
return max;
}
Example 3: maximum arrays size in java
int arr[] = new int[N];
Example 4: max array number in java
Integer[] num = { 2, 4, 7, 5, 9 };
int min1 = Collections.min(Arrays.asList(num));
int max1 = Collections.max(Arrays.asList(num));
System.out.println(min1);
System.out.println(max1);