This is the third solution to find the biggest number from the given array of integers, using stream method of Arrays class. This stream uses filter(0, max(), and getAsInt() methods.
import java.util.Arrays;
public class biggest {
public static void main(String [] args) {
int [] arrNums= {45,89,23,194,71,91,26};
/* Use the stream method of Arrays class to find the first, and
the second biggest in the given array */
int firstBig=Arrays.stream(arrNums).max().getAsInt();
int secondBig=Arrays.stream(arrNums).filter(e->e!=firstBig).max().getAsInt();
System.out.println("The first biggest number in the array is="+firstBig);
System.out.println("The second biggest number in the array is="+secondBig);
}
}
Output:
The first biggest number in the array is=194
The second biggest number in the array is=91

Leave a comment