Summing multiple different fields in a list of objects using the streams api?
<p>In Java 8, if I have a list of Objects like this:</p>

<pre><code> MyObject
   double a;
   double b;
   double c;
</code></pre>

<p>I want to get the totals of each of these fields in the list of objects. One way I can to do it, is as follows:  </p>

<pre><code>double totalA = myListOfObjects.stream().map(e -&gt; e.getA()).reduce(0.0, (x, y) -&gt; x + y);
double totalB = myListOfObjects.stream().map(e -&gt; e.getB()).reduce(0.0, (x, y) -&gt; x + y);
double totalC = myListOfObjects.stream().map(e -&gt; e.getC()).reduce(0.0, (x, y) -&gt; x + y);  
</code></pre>

<p>But is there away to combine this into one pass through the list of objects usng the streams api? If I just wrote a for/while loop (see below) and manually added up the 3 totals, that would seem more efficent then the above 3 lines of code)</p>

<pre><code>for (MyObject obj: myListOfObjects) {
    totalA += obj.getA();
    totalB += obj.getB();
    totalC += obj.getC();
}
</code></pre>

<p>Thanks</p>