Java Minimum and Maximum values in Array Java Minimum and Maximum values in Array arrays arrays

Java Minimum and Maximum values in Array


getMaxValue(array);// get smallest numbergetMinValue(array);

You are calling the methods but not using the returned values.

System.out.println(getMaxValue(array));System.out.println(getMinValue(array)); 


You can try this too, If you don't want to do this by your method.

    Arrays.sort(arr);    System.out.println("Min value "+arr[0]);    System.out.println("Max value "+arr[arr.length-1]);


Imho one of the simplest Solutions is: -

//MIN NUMBERCollections.sort(listOfNumbers);listOfNumbers.get(0);//MAX NUMBERCollections.sort(listOfNumbers);Collections.reverse(listOfNumbers);listOfNumbers.get(0);