title: How to write Iterator for a list?
body: <p>I have a class implementing List interface and storing data in an array of Objects. Now I need to write Iterator method for my class. How to get started ? I thought about writing a subclass implementing Iterator interface. Object of the class will have parameters of current index and last index. At each call to next/hasNext those parameters will be modified. Is this approach correct ? But then there is a problem with remove() method, since it should allow to delete object of class calling my iterator. How to solve this ? Also what should happen in iterator() method of my main class ?</p>
  
  <p>My pseudocode:</p>
  
  <pre><code>class MyCollection&lt;T&gt; implements List&lt;T&gt;{
      T[] tab;
  
      MyCollection(int len) {
          tab = (T[])new Object[len];
      }
      public Iterator iterator(){
      }
  }
  
  class MyIterator&lt;T&gt; implements Iterator {
  
      private int current;
      private int last;
  
      public void remove(){
      }
  
      public T next(){
  
      }
  
      public boolean hasNext(){
  
      }
  
  }
  </code></pre>