title: How to limit the number of items that can be added to a list in a list
body: <p>I have a list of lists in Java which has 3 lists of integers in it.</p>
  
  <pre><code>List&lt;List&lt;Integer&gt;&gt; L;
           myList = new ArrayList&lt;&gt;();
           for(int i=0; i&lt;3; i++){
                  myList.add(new ArrayList&lt;Integer&gt;());
           }
  myList.get(0).add(1);
  myList.get(0).add(2);
  myList.get(0).add(3);
  myList.get(0).add(4);
  myList.get(1).add(1);
  myList.get(1).add(2);
  .
  .
  .
  </code></pre>
  
  <p>My problem is that the number of the items that can be added to each of lists is unlimited in my code, but I want to limit the number of the items that each list can get. For example, each list can get only 4 items and when the 5th item is received by one of these lists, I need a shift to the left so the 5th item can be added to the list.
  Here is an example of what I intend to do:</p>
  
  <blockquote>
    <p>At first: myList = [[1,2,3,4],[1,2,3,4],[1,2,3,4]]</p>
    
    <p>After the 5th item is added to the first list of myList: myList =
    [[2,3,4,5],[1,2,3,4],[1,2,3,4]]</p>
  </blockquote>
  
  <p>I tried to limit the number by something like this:</p>
  
  <pre><code>for(int i=0; i&lt;3; i++){
          myList.add(new ArrayList&lt;Integer&gt;(4));
   }
  </code></pre>
  
  <p>but it didn't work. How can I do this?</p>