Java Iterator to Iterable iterable(final Iterator iterator)

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

Description

Makes an Interator iterable with foreach

License

Apache License

Parameter

Parameter Description
I a parameter
iterator a parameter

Declaration

public static <I> Iterable<I> iterable(final Iterator<I> iterator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;

public class Main {
    /**/*from w w  w  .  jav  a 2  s.c  o  m*/
      * Makes an Interator iterable with foreach
      * 
      * @param <I>
      * @param iterator
      * @return
      */
    public static <I> Iterable<I> iterable(final Iterator<I> iterator) {
        return new Iterable<I>() {

            @Override
            public Iterator<I> iterator() {
                return iterator;
            }
        };
    }
}

Related

  1. iterable(final Iterator it)
  2. iterable(final Iterator iterator)
  3. iterable(final Iterator iter)
  4. iterable(Iterator iterator)
  5. toIterable(final Iterator iterator)
  6. toIterable(final Iterator iterator)