
Finding the max/min value in an array of primitives using Java
Mar 13, 2015 · You can simply use the new Java 8 Stream s but you have to work with int. The stream method of the utility class Arrays gives you an IntStream on which you can use the min …
Java Minimum and Maximum values in Array - Stack Overflow
Aug 26, 2016 · 1. calling getMaxValue(),getMinValue() methods before array initialization completes. 2.Not storing return value returned by the getMaxValue(),getMinValue() methods.
Java Program to Find Largest Element in an Array
Apr 9, 2025 · The most common method to find and print the largest element of a Java array is to iterate over each element of the array and compare each element with the largest value.
java - Can you use Math.max with an array? - Stack Overflow
Jun 26, 2014 · Can you use Math.max with an array? No, but... If you're using Java 8, you can use streams: Otherwise you can write a simple utility method to do it for you: if (array.length == …
How to Add an Element to an Array in Java? - GeeksforGeeks
Jan 3, 2025 · How to Add an Element to an Array in Java? Given an array of size n, the task is to add an element x in this array in Java. The size of the array cannot be changed dynamically in …
Find max or min value in an array of primitives using Java
Apr 9, 2025 · 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 …
Finding Min/Max in an Array with Java - Baeldung
Jan 8, 2024 · In this short tutorial, we’re going to see how to find the maximum and the minimum values in an array, using Java 8’s Stream API. We’ll start by finding the minimum in an array of …
Java Math max () - Programiz
// assign first element of array as maximum value int max = arr[0]; for (int i = 1; i < arr.length; i++) { max = Math.max(max, arr[i]); System.out.println("Maximum Value: " + max); In the above …
Java – Finding minimum and maximum values in an array
Sep 11, 2022 · In this example we are finding out the maximum and minimum values from an int array. class MinMaxExample { public static void main (String args []) { int array [] = new int [] …
Max element of an array in Java - Stack Overflow
Mar 11, 2014 · I suggest you do it like so, Start with max = a[0]; then loop with j from 1 to a.length. Compare a[j] to max, that is if a[j] > max then set max = a[j];.