Adapt the specified Enumeration to the Iterator interface. - Android java.util

Android examples for java.util:Iterator

Description

Adapt the specified Enumeration to the Iterator interface.

Demo Code

// Copyright (c) 2003-present, Jodd Team (jodd.org). All Rights Reserved.
//package com.book2s;

import java.util.Enumeration;
import java.util.Iterator;

public class Main {
    /**//w w w  .j  a v a2  s  . c om
     * Adapt the specified <code>Enumeration</code> to the <code>Iterator</code> interface.
     */
    public static <E> Iterator<E> asIterator(final Enumeration<E> e) {
        return new Iterator<E>() {
            public boolean hasNext() {
                return e.hasMoreElements();
            }

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

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

Related Tutorials