dibendu-g / find-max-or-min-value-in-an-array-of-primitives-using-java Goto Github PK
View Code? Open in Web Editor NEWJava as a whole is a language that generally requires a lot of coding to execute specific tasks. Hence, having shorthand for several utilities can be beneficial. One such utility, to find maximum and minimum element in array is explained in this article using “aslist()“. aslist() type casts a list from the array passed in its argument. This function is defined in “Java.utils.Arrays“. To get the minimum or maximum value from the array we can use the Collections.min() and Collections.max() methods. But as this method requires a list type of data we need to convert the array to list first using above explained “aslist()” function. Note: “The array you are are passing to the Arrays.asList() must have a return type of Integer or whatever class you want to use”, since the Collections.sort() accepts ArrayList object as a parameter. Note: If you use type int while declaring the array you will end up seeing this error: “no suitable method found for min(List<int[]>)”