java - Is there possibility of sum of ArrayList without looping -


is there possibility of sum of arraylist without looping?

php provides sum(array) give sum of array.

the php code like

$a = array(2, 4, 6, 8); echo "sum(a) = " . array_sum($a) . "\n"; 

i wanted same in java:

list tt = new arraylist(); tt.add(1); tt.add(2); tt.add(3); 

once out (march 2014) you'll able use streams:

if have list<integer>

int sum = list.stream().maptoint(integer::intvalue).sum(); 

if it's int[]

int sum = intstream.of(a).sum(); 

Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -