Write a Program to find the Maximum element in an array
Categories: Java 8(JDK1.8) Java Java Examples
package r4r.co.in;
import java.util.Arrays;
import java.util.Comparator;
public class MaximumOfGivenArray {
public static void main(String[] args) {
//Write a Program to find the Maximum element in an array
int[] arr= {1,2,3,4,5,66,6,7,7,4,8};
int max=Arrays.stream(arr).max().getAsInt();
System.out.println(max);
Integer[] arrInteger= {2,3,45,56,67,27,76,83,28,228,338,4343};
Integer maxValue=Arrays.stream(arrInteger).max(Comparator.naturalOrder()).get();
System.out.println(maxValue);
}
}
Output
66
4343