title: Java Iterators and Lists - add to 3rd list
body: <p>I have two LinkedList and I want to add the Integeres from both into a third List. I'm trying to add the first element from the first list, then the first element from the second list etc.</p>
  
  <p>I need the final output to be </p>
  
  <pre><code>[1, 6, 2, 7, 3, 8, 4, 9, 5, 10, 11, 12].
  </code></pre>
  
  <p>but I keep getting</p>
  
  <pre><code>[1, 6, 2, 7, 3, 8, 4, 9, 5, 10].
  </code></pre>
  
  <p>How do I fix it?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.Iterator;
  import java.util.LinkedList;
  import java.util.List;
  public class Ex11_2_alternate {
  
  public static void main(String[] args) {
  
      List&lt;Integer&gt; list = new LinkedList&lt;&gt;();
      List&lt;Integer&gt; list2 = new LinkedList&lt;&gt;();
  
      list.addAll(Arrays.asList(1,2,3,4,5));
      list2.addAll(Arrays.asList(6,7,8,9,10,11,12));
  
      alternate(list,list2);
  
  }
  private static void alternate(List&lt;Integer&gt; list, List&lt;Integer&gt; list2) {
  
      List&lt;Integer&gt; list3 = new LinkedList&lt;&gt;();
  
      Iterator&lt;Integer&gt; itr = list.iterator();
      Iterator&lt;Integer&gt; itr2 = list2.iterator();
  
      while (itr.hasNext() &amp; itr2.hasNext()) {
          int element = itr.next();
          int element2 = itr2.next();
  
          if ((element | element2) != 0) {
              list3.add(element);
              list3.add(element2);
          }
  
  
        }
      System.out.println("After ... : " + list3);
     }
  
  
  }
  </code></pre>