title: Is mapToDouble() really necessary for summing a List<Double> with Java 8 streams?
body: <p>As far as I can tell, the way to sum a <code>List&lt;Double&gt;</code> using Java 8 streams is this:</p>
  
  <pre><code>List&lt;Double&gt; vals = . . . ;
  double sum = vals.stream().mapToDouble(Double::doubleValue).sum();
  </code></pre>
  
  <p>To me, the <code>mapToDouble(Double::doubleValue)</code> seems kind of crufty - just the sort of boilerplate "ceremony" that lambdas and streams were supposed to dispense with.</p>
  
  <p>Best practices tell us to prefer <code>List</code> instances over arrays, and yet for this sort of summing, arrays seem cleaner:</p>
  
  <pre><code>double[] vals = . . . ;
  double sum = Arrays.stream(vals).sum();
  </code></pre>
  
  <p>Granted, one could do this:</p>
  
  <pre><code>List&lt;Double&gt; vals = . . . ;
  double sum = vals.stream().reduce(0.0, (i,j) -&gt; i+j);
  </code></pre>
  
  <p>But that <code>reduce(....)</code> is so much longer than <code>sum()</code>.</p>
  
  <p>I get that this has to do with the way streams need to be retrofitted around the Java's non-object primitives, but still, am I missing something here?  Is there some way to squeeze autoboxing in to make this shorter?  Or is this just the current state of the art?</p>
  
  <hr>
  
  <h2>Update - Answers Digest</h2>
  
  <p>Here is a digest of answers below. While I have a summary here, I urge the reader to peruse the answers themselves in full.</p>
  
  <p>@dasblinkenlight explains that some kind of unboxing will always be necessary, due to decisions made further back in the history of Java, specifically in the way generics were implemented and their relationship to the non-object primitives. He notes that it is theoretically possible for the compiler to intuit the unboxing and allow for briefer code, but this has not yet been implemented.</p>
  
  <p>@Holger shows a solution that is very close to the expressiveness I was asking about:</p>
  
  <pre><code>double sum = vals.stream().reduce(0.0, Double::sum);
  </code></pre>
  
  <p>I was unaware of the new static <code>Double.sum()</code> method.  Added with 1.8, it seems intended for the very purpose I was describing.  I also found <code>Double.min()</code> and <code>Double.max()</code>.  Going forward, I will definitely use this idiom for such operations on <code>List&lt;Double&gt;</code> and similar.</p>