title: How to handle if sum of integer array exceeds int max value(2147483647) using Arrays Stream?
body: <p>I have an integer array and want to sum all it's elements. It's working fine as far as sum is less than or equal to int max value(2147483647) but it's failing as soon as sum exceeds int max value. Below is the example-:</p>
  
  <pre><code>int [] iArr = new int[]{2147483646 , 1 , 1};
      System.out.println(Arrays.stream(iArr).sum());
  </code></pre>
  
  <blockquote>
    <p>Result-: -2147483648</p>
  </blockquote>
  
  <p>As we can see above result is incorrect. I know that it can be resolved by using long array instead if int array as below.</p>
  
  <pre><code>long [] iArr = new long[]{2147483646 , 1 , 1};
      System.out.println(Arrays.stream(iArr).sum());
  </code></pre>
  
  <blockquote>
    <p>Result-: 2147483648</p>
  </blockquote>
  
  <p>But I don't want to use long array because I know that maximum size limit of elements of array is with in int max value(2147483647). Hence I don't want to waste memory. Is there any other way to sum of integer array which(sum of elements of array) exceeds int max value(2147483647) using Array Stream?</p>