Source Code : Wrapping an Iterator around an Enumeration

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Wrapping an Iterator around an Enumeration

   
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;

public class EnumerationIterator1 {
  public static Iterator iterator(final Enumeration e) {
    return new Iterator() {
      public boolean hasNext() {
        return e.hasMoreElements();
      }

      public Object next() {
        return e.nextElement();
      }

      public void remove() {
        throw new UnsupportedOperationException();
      }
    };
  }

  public static void main(String args[]) {
    String elements[] = { "Java", "Source", "and", "Support", "." };
    Vector v = new Vector(Arrays.asList(elements));
    Enumeration e = v.elements();
    Iterator itor = EnumerationIterator1.iterator(e);
    while (itor.hasNext()) {
      System.out.println(itor.next());
    }
  }
}

           
         
    
    
  

Thank with us