Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can some please explain to me what Array.stream is and specifically what is happ

ID: 3812671 • Letter: C

Question

Can some please explain to me what Array.stream is and specifically what is happening in that two lines of max and min.

from what i assume and understand from looking at the code is that array.stream goes through the numberElements and picks u the max or min.

by the way numberElements is an array which contains [1,2,5]

and i know the answer which maximumDifference is =4;

void calculateDifference() { int max = Arrays.stream(numberElements).max().getAsInt(); int min = Arrays.stream(numberElements).min().getAsInt(); maximumDifference = max - min ; }

Explanation / Answer

void calculateDifference() {

    int max = Arrays.stream(numberElements).max().getAsInt();
    int min = Arrays.stream(numberElements).min().getAsInt();
    maximumDifference = max - min ;
}


static IntStream   stream(int[] array) : In Arrays class
   Returns a sequential IntStream with the specified array as its source.

OptionalInt   max() : IntStream class
Returns an OptionalInt describing the maximum element of this stream, or an empty optional if this stream is empty.

int   getAsInt() : In OptionalInt class
If a value is present in this OptionalInt, returns the value, otherwise throws NoSuchElementException.