title: Batch processing an ArrayList with LongStream using Java 8
body: <p>I am trying to process an ArrayList with content of Long type as in the given example below using Java 8's LongStream but I get the below error. </p>
  
  <pre><code>import java.util.*;
  import java.util.stream.*;
  
   public class HelloWorld{
   public static void main(String []args){
      List&lt;Long&gt; data=new LinkedList();
       for(Long j=0L;j&lt;300L;j++){
          data.add(j);
      }
     int BATCH = 10;
  
     LongStream.range(0, (data.size()+BATCH-1)/BATCH)
       .mapToLong(i -&gt; data.subList(i*BATCH, Math.min(data.size(), (i+1)*BATCH)))
       .forEach(batch -&gt; process(batch));
   }
  
  static void process(List&lt;Long&gt; list){
       System.out.println(list);
   }
  }
  </code></pre>
  
  <p>But I get the below exception. I have tried with mapToLong insted of map but mapToLong is not recognzied</p>
  
  <pre><code>$javac HelloWorld.java
   HelloWorld.java:13: error: incompatible types: possible lossy 
   conversion from long to int
       .map(i -&gt; data.subList(i*BATCH, Math.min(data.size(), 
   (i+1)*BATCH)))
                               ^
  HelloWorld.java:14: error: incompatible types: long cannot be 
  converted to List&lt;Long&gt;
       .forEach(batch -&gt; process(batch));
                                 ^
   2 errors
  </code></pre>