Java Iterator iterable(Iterator iterator)

Here you can find the source of iterable(Iterator iterator)

Description

Allow iterator to be used in a for each loop.

License

Open Source License

Parameter

Parameter Description
iterator a parameter
T a parameter

Declaration

public static <T> Iterable<T> iterable(Iterator<T> iterator) 

Method Source Code

//package com.java2s;
/**//  w ww  .  j  a va  2  s.co m
 * Find Security Bugs
 * Copyright (c) Philippe Arteau, All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 */

import java.util.*;

public class Main {
    /**
     * Allow iterator to be used in a for each loop.
     * @param iterator
     * @param <T>
     * @return
     */
    public static <T> Iterable<T> iterable(Iterator<T> iterator) {
        return new Iterable<T>() {
            @Override
            public Iterator<T> iterator() {
                return iterator;
            }
        };
    }
}

Related

  1. hex(Iterator it)
  2. implode(Iterator it)
  3. isBlank(Iterator iterator)
  4. isIterator(Class clazz)
  5. isPrefixOf(Iterator pref, Iterator target)
  6. length(Iterator iter)
  7. limit(final Iterator iterator, final int limit)
  8. listOfIterator(Iterator iterator)
  9. makeCollection(final Iterator i)