title: Java Iterate over List in pairs each 2 elements
body: <p>I have an <code>ArrayList</code> and I want to iterate over it each 2 elements, like this: ([1,2], [3, 4], [5, 6])</p>
  
  <p>Currently I'm able to iterate the list like this: ([1,2], [2, 3], [3, 4]) but this is not the result I want.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>Iterator&lt;MyObject&gt; iterator = myList.iterator();
          if (iterator.hasNext()) {
              MyObject o1 = iterator.next();
              while (iterator.hasNext()) {
                  final MyObject o2 = iterator.next();
                  //Do my stuff
                  o1 = o2;
              }
          }
  </code></pre>
  
  <p>I know that should be quite simple but I don't see it.</p>
  
  <p>I got the code from this link: <a href="https://stackoverflow.com/questions/17453022/idiom-for-pairwise-iteration-through-a-sorted-collection">Link 1</a></p>
  
  <p>I've also seen these post:</p>
  
  <p><a href="https://stackoverflow.com/questions/16033711/java-iterating-over-every-two-elements-in-a-list">Link 2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/22465223/iterating-through-an-array-2-items-at-a-time">Link 3</a></p>