Is there possibility of sum of ArrayList without looping

后端 未结 13 1402
无人共我
无人共我 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:56

    Then write it yourself:

    public int sum(List list) {
         int sum = 0; 
    
         for (int i : list)
             sum = sum + i;
    
         return sum;
    }
    

提交回复
热议问题