# How to find minimum and maximum values in an array in java

33 views

## Problem:

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 };

## Solution:

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.

Thanks

## Related questions

3 views
Problem: I will request someone to answer how to find the Java program minimum and maximum number in an array?
1 vote
6 views
Problem: After giving a code it does not display the minimum and miximum values&raquo; Java program to find minimum and maximum number in an array.
358 views
I am new to this. I just want to know how to do that?
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);     } }
1 vote
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.
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
2 views
Problem: Can someone tell me program to find duplicate numbers in an array in java ?