Sum Of Array Elements Using Java 8 Stream Reduce | Sum | How Reduce Works | InterviewDOT

preview_player
Показать описание

Sum Of Array Elements Using Java 8 Stream Reduce | Sum | How Reduce Works | InterviewDOT

sum() The Stream API provides us with the mapToInt() intermediate operation, which converts our stream to an IntStream object. This method takes a mapper as a parameter, which it uses to do the conversion, then, we can call the sum() method to calculate the sum of the stream's elements.

Reducing is the repeated process of combining all elements. reduce operation applies a binary operator to each element in the stream where the first argument to the operator is the return value of the previous application and second argument is the current stream element.

Рекомендации по теме