title: Converting an Enumeration to Iterator
body: <p>I have a problem on a worksheet which is to create an adapter to convert an Enumeration to an Iterator. When I try to run the following code I get a null pointer exception.</p>
  
  <pre><code>import java.util.Vector;
  import java.util.Arrays;
  import java.util.Enumeration;
  import java.util.Iterator;
  
  public class ConvertEnumeration {
  
      public static void main(String [] args) {
  
          int [] ourArray = {0,1,2,3,4,5,6,7,8,9};
          Vector vector = new Vector(Arrays.asList(ourArray));
  
          //Get Enumerator 
          Enumeration enumerator = vector.elements();
  
          EnumerationToIterator enumToIt = new EnumerationToIterator(enumerator);
          while(enumToIt.hasNext()) {
              System.out.println(enumToIt.next());
          }
      }
  
  }
  
  
  //Convert our enumeration to Iterator!
  class EnumerationToIterator implements Iterator {
  
      //Our enumeration
      Enumeration enmueration;
  
      //Constructor
      public EnumerationToIterator(Enumeration enmueration){
          enmueration = this.enmueration;
      }
  
      //Our Methods
      public boolean hasNext(){
          return enmueration.hasMoreElements();
      }
  
      public Object next(){
          return enmueration.nextElement();
      }
  
      public void remove(){
          throw new UnsupportedOperationException();
      }
  
  }
  </code></pre>
  
  <p>Another point to note is that I can not print out the int's from the Enumeration after I have created it in the first place.</p>