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

Android examples for java.util:Iterator

Description

Adapt the specified Iterator to the Enumeration 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 {
    public static void main(String[] argv) {
        Iterator iter = java.util.Arrays.asList("asdf", "book2s.com")
                .iterator();//from www.j a v  a2  s  .c  om
        System.out.println(asEnumeration(iter));
    }

    /**
     * Adapt the specified <code>Iterator</code> to the
     * <code>Enumeration</code> interface.
     */
    public static <E> Enumeration<E> asEnumeration(final Iterator<E> iter) {
        return new Enumeration<E>() {
            public boolean hasMoreElements() {
                return iter.hasNext();
            }

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

Related Tutorials