集册 Java实例教程 设置迭代器

设置迭代器

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

423
要设置的迭代器

/*

  You may freely copy, distribute, modify and use this class as long

  as the original author attribution remains intact.  See message

  below.


  Copyright (C) 2003 Christian Pesch. All Rights Reserved.

 */

//package com.nowjava;//来自 nowjava.com

import java.util.*;


public class Main {

    public static <T> Set<T> toSet(Iterator<? extends T> iteration) {

        Set<T> elements = new HashSet<T>(1);

        while (iteration.hasNext()) {

            elements.add(iteration.next());

        }

        return elements;

    }

}