Is there possibility of sum of ArrayList without looping?
ArrayList
PHP provides sum(array) which will give the sum of array.
sum(array)
The PHP code is
Write a util function like
public class ListUtil{ public static int sum(List list){ if(list==null || list.size()<1) return 0; int sum = 0; for(Integer i: list) sum = sum+i; return sum; } }
Then use like
int sum = ListUtil.sum(yourArrayList)