0
whats the 0 for ?
whats the 0 for ? code: import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) { List <Integer> myList = Arrays.asList(1 , 5 ,4 ,4 ,3 ,3); int sum = myList.stream().reduce(0 , (num1 , num2) -> num1 + num2); //the 0 in this line System.out.println(sum); } }
3 odpowiedzi
+ 4
Not good with Java, but usually, a reduce function uses something they call an accumulator, the values in the list will be added into the accumulator.
Please cmiiw about this, kinda not sure 🙏
0
👍🏻👍🏻👍🏻thanks!