Is there possibility of sum of ArrayList without looping

后端 未结 13 1442
无人共我
无人共我 2020-11-27 04:24

Is there possibility of sum of ArrayList without looping?

PHP provides sum(array) which will give the sum of array.

The PHP code is

13条回答
  •  孤街浪徒
    2020-11-27 04:50

    If you know about the map function, then you know that a map is also can be recursive loop or recursive loop. But obviously you have to reach each element for that. so, I could not work out the Java 8, because some syntax mismatch but wanted a very short so this is what I got.

    int sum = 0
    for (Integer e : myList) sum += e;
    

提交回复
热议问题