title: Java 8: How to turn a list into a list of lists using lambda
body: <p>I'm trying to split a list into a list of list where each list has a maximum size of 4.</p>
  
  <p>I would like to know how this is possible to do using lambdas.</p>
  
  <p>Currently the way I'm doing it is as follow:</p>
  
  <pre><code>List&lt;List&lt;Object&gt;&gt; listOfList = new ArrayList&lt;&gt;();
  
  final int MAX_ROW_LENGTH = 4;
  int startIndex =0;
  while(startIndex &lt;= listToSplit.size() )    
  {
      int endIndex = ( ( startIndex+MAX_ROW_LENGTH ) &lt;  listToSplit.size() ) ? startIndex+MAX_ROW_LENGTH : listToSplit.size();
      listOfList.add(new ArrayList&lt;&gt;(listToSplit.subList(startIndex, endIndex)));
      startIndex = startIndex+MAX_ROW_LENGTH;
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>It seems that there isn't a simple way to use lambdas to split lists. While all of the answers are much appreciated, they're also a wonderful example of when lambdas do not simplify things.</p>