• Register
3 votes


Hello good souls,

I am a new student of Java. I just started learning and trying to solve java problems. Right now, I am working with the arrays. I can do some basic things with an array. I am finding something more advance problems of an array. Thus I thought to find the maximum and minimum value in an array. Still, I don’t know is it an advance level problem or not but for me it is! So, my question is simple, how to find minimum and maximum values in an array in java?

Let’s say I have an array

Integer[] num = { 2, 4, 6, 5, 8 }; 

Thanks in advance for your effort.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

0 votes


Thanks for your specific and to the point question. You asked the question very clearly. Well, you have an array declared in your program, you can easily find out the Minimum and Maximum value of it. You can either use iteration or pre-defined function to do this.

As you said in your question, you want to proceed to the advance level, I decided to show you it by using a function. I hope you already know how to use or handle an iteration.

So, let’s have a look into the program below:

import java.util.Arrays; 
import java.util.Collections; 
public class MinNMax { 
public static void main(String[] args) 
        Integer[] num = { 2, 4, 6, 5, 8 }; 
        int min = Collections.min(Arrays.asList(num)); 
        int max = Collections.max(Arrays.asList(num)); 
        System.out.println("The minimum number of this array is : " + min); 
        System.out.println("The maximum number of this array is : " + max); 

aslist() typecasts a list from the array passed in its argument. This function is defined in “Java.utils.Arrays“ library. To bring out the maximum and minimum number from the array I used Collections.max() and Collections.min() methods.


13 9 6
94,240 points

Related questions

0 votes
0 answers 3 views
Problem: I will request someone to answer how to find the Java program minimum and maximum number in an array?
asked Apr 1 zayed1 30.9k points
1 vote
1 answer 6 views
Problem: After giving a code it does not display the minimum and miximum values» Java program to find minimum and maximum number in an array.
asked Mar 30 PkGuy 13.1k points
0 votes
1 answer 358 views
I am new to this. I just want to know how to do that?
asked Nov 5, 2020 TeamScript 13.5k points
0 votes
1 answer 15 views
Maximum and minimum in a C ++ vector with numbers from a file I'm trying to make a C ++ program that sends 100 random numbers to a file, then collects them and gets the largest number and the smallest number. I have tried to do this by putting the hundred numbers in a vector and taking the ...   printf ("The greater is% d \ n", greater);         printf ("The minor is% d \ n", minor);     } }
asked Aug 15, 2020 game 4.6k points
1 vote
1 answer 28 views
Problem: Hello Kodlogs, I have got a question from my fellow (java learner) friend and the question is: find the largest number in an array java I know about the array and I can print all the values sequentially. Moreover, I can add two different values of an array in ... Could any of you please give me a proper solution and tell me how to find the largest number in an array java? Thanks to all.
asked Mar 29, 2020 Gavin 15.3k points
0 votes
2 answers 5 views
Problem: Do you have any suggestions about how I can resolve this? Find maximum of minimum for every window size in a given array
asked Mar 29 tuhin1 48.4k points
0 votes
1 answer 2 views
Problem: Can someone tell me program to find duplicate numbers in an array in java ?
asked Mar 30 Madhav96 2.3k points
0 votes
1 answer 71 views
Problem: Hi there! I have started learning java just recently and I found a problem in a programming exercise in which I have to find the second largest number in a given array using programming. I know how to find the largest number, but I am facing difficulty ... number. Can anybody here help me solve the problem? Also, provide the example program so that I can understand it better. Thanks!
asked Jan 2 Code Learner 9.2k points
1 vote
1 answer 4 views
Problem: Any expert to put light on this issue. Program to find maximum and minimum in python.
asked Mar 30 PkGuy 13.1k points
0 votes
1 answer 32 views
In C ++ I made a function that, given a length, creates an array and returns it. Finally I show their values outside the function. I was investigating and they say that in C ++ it is not possible to return an array, and for this there are two alternatives, one is to return a pointer, and another is to pass ... () {     int * arr = create_array (10);     cout << arr [8] << "" << arr [9] << "\ n"; }
asked Aug 16, 2020 game 4.6k points