title: How to find sum with forEach and lambda expression in Java?
body: <p>The following snippet does not compile. How to find the <code>sum</code> using <code>forEach</code> as shown below?</p>
  
  <pre><code>private int Sum(ArrayList&lt;Integer&gt; inputs) {
      int sum = 0;
  
      inputs.stream().forEach(x -&gt; sum += x);
  
      return sum;
  }
  </code></pre>