iterable From Iterator - Android java.util

Android examples for java.util:Iterator

Description

iterable From Iterator

Demo Code


//package com.book2s;

import java.util.Iterator;

public class Main {
    public static void main(String[] argv) {
        Iterator iterator = java.util.Arrays.asList("asdf", "book2s.com")
                .iterator();/* w ww  . j  a  va2s .co m*/
        System.out.println(iterableFromIterator(iterator));
    }

    public static <T> Iterable<T> iterableFromIterator(
            final Iterator<T> iterator) {
        return new Iterable<T>() {

            public Iterator<T> iterator() {
                return iterator;
            }
        };
    }
}

Related Tutorials