title: Provide an iterator over the contents of two lists simultaneously?
body: <p>Suppose I have this:</p>
  
  <pre><code>public class Unit&lt;MobileSuit, Pilot&gt; {
  
      ...
  
      List&lt;MobileSuit&gt; mobileSuits;
      List&lt;Pilot&gt; pilots;
  
      ...
  }
  </code></pre>
  
  <p>And I would like to iterate through the pair of each  in the simplest way outside of that class. How should I go about doing that? I thought about doing this:</p>
  
  <pre><code>public class Unit&lt;MobileSuit, Pilot&gt; {
  
      ...
      Iterator&lt;MobileSuit&gt; iteratinMechas;
      Iterator&lt;Pilot&gt; iteratinPeople;
  
      class IteratorCustom&lt;MobileSuit, Pilot&gt; implements Iterator {
  
          public boolean hasNext() {
              return iteratinMechas.hasNext() &amp;&amp; iteratinPeople.hasNext();
          }
  
          public void remove() {
              iteratinMechas.remove();
              iteratinPeople.remove();
          }
  
          public Object next() {
              // /!\
          }
  
      }
  
      public Iterator iterator() {
          return new IteratorCustom&lt;MobileSuit, Pilot&gt;(mobileSuits, pilots);
      }
  }
  </code></pre>
  
  <p>Something along those lines.</p>
  
  <p>Anyway, the problem is that I can't really return just a single object from next(), and I also can't have a Iterator take more than one type. So, any thoughts?</p>
  
  <p>Also, I can't make a new class to combine MobileSuit and Pilot. I need to keep them separate, even though I'm iterating through both at a time. The reason is that there might be Mobile Suits that have no pilots, and I'm not sure how to fix that by keeping them at the same class. This class needs to be processed in other places, so I'd have to unify a interface around that and a lot of other stuff. Basically, assume MobileSuit and Pilot need to be separated.</p>