I have two ArrayLists named A and B, an equal size containing some numbers. Now I want to calculate something like this:
int sum = 0;
for(int i=0; i<A.size() && i<B.size(); i++) {
sum += A.get(i)*B.get(i);
}
How can I achieve what I am doing above by calculating the sum using Java 8 functions (streams, lambda expressions, etc.) without using any additional custom methods?
source
share