iterator As Enumeration - Java Collection Framework

Java examples for Collection Framework:Iterator

Description

iterator As Enumeration

Demo Code

// Licensed to the Apache Software Foundation (ASF) under one
//package com.java2s;
import java.util.Enumeration;
import java.util.Iterator;

public class Main {
    public static <T> Enumeration<T> iteratorAsEnumeration(
            final Iterator<T> it) {
        return new Enumeration<T>() {
            public boolean hasMoreElements() {
                return it.hasNext();
            }/*w  w  w .j a v  a2s . c o  m*/

            public T nextElement() {
                return it.next();
            }
        };
    }
}

Related Tutorials