集册 Java实例教程 枚举迭代

枚举迭代

欢马劈雪     最近更新时间:2020-01-02 10:19:05

401
枚举为Iterable

// Licensed to the Apache Software Foundation (ASF) under one

//package com.nowjava;

import java.util.Enumeration;

import java.util.Iterator;
/** 
 来自 时   代    Java - nowjava.com**/


public class Main {

    public static <T> Iterable<T> enumerationAsIterable(

            final Enumeration<T> e) {

        return new Iterable<T>() {

            public Iterator<T> iterator() {

                return new Iterator<T>() {

                    public boolean hasNext() {

                        return e.hasMoreElements();

                    }


                    public T next() {

                        return e.nextElement();//来 自 NowJava.com - 时  代  Java

                    }


                    public 
展开阅读全文