title: Calculating Luhn Algorithm with Java 8 Stream
body: <p>I am trying to validate an <a href="https://en.wikipedia.org/wiki/International_Mobile_Station_Equipment_Identity" rel="nofollow">IMEI</a> number with the Help of Stream API in Java 8.</p>
  
  <pre><code>private void ValidateIMEI() {
      field //a field holding an IMEI Number
              .getText().chars()
              .map(this::ConvertASCIIToNumer);
  }
  </code></pre>
  
  <p>The part I am stuck is the doubling the even number and divide it by 10.</p>
  
  <p>Initially, I tried the traditional for loop:</p>
  
  <pre><code>private void ValidateIMEI() {
      int[] numbers = field //a field holding an IMEI Number
              .getText().chars()
              .map(this::ConvertASCIIToNumer).toArray();
  
      int sum = 0;
      for (int i = 0; i &lt; numbers.length; i++) {
          //Double the even number and divide it by 10. add quotient and remainder
          if ((numbers[i]+1) % 2 == 0) {
              numbers[i] = numbers[i] * 2;
              numbers[i] = numbers[i] / 10 + numbers[i] % 10;
          }
          sum += numbers[i];
      }
  
      if (sum%10==0) {
          status.setText("Valid");
      }
      else{
          status.setText("InValid");
      }        
  }
  </code></pre>
  
  <p>But the code is broken and most specifically using For loop which I don't want.</p>
  
  <p>So, any one can help to implement <a href="https://en.wikipedia.org/wiki/Luhn_algorithm" rel="nofollow">Luhn algorithm</a> with only Stream API in Java 8?</p>
  
  <p>Code for ConvertASCIIToNumer:</p>
  
  <pre><code>private int ConvertASCIIToNumer(int value) {
      return Character.digit(value, 10);
  }
  </code></pre>