Check out example codes for "max in array java". It will help you in understanding the concepts better.

Code Example 1

// Initializing array of integers 
        Integer[] num = { 2, 4, 7, 5, 9 }; 
// using Collections.min() to find minimum element 
        // using only 1 line. 
        int min = Collections.min(Arrays.asList(num)); 
  
        // using Collections.max() to find maximum element 
        // using only 1 line. 
        int max = Collections.max(Arrays.asList(num));

Code Example 2

import java.util.Arrays;

public class apples {

  public static void main(String[] args) {
    int a[] = {2,5,3,7,8};
    Arrays.sort(a);

     int min =a[0];
    System.out.println(min);
    int max= a[a.length-1];
    System.out.println(max);

  }

}

Code Example 3

public static double arrayMax(double[] arr) {
    double max = Double.NEGATIVE_INFINITY;

    for(double cur: arr)
        max = Math.max(max, cur);

    return max;
}

Learn ReactJs, React Native from akashmittal.com