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

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -