Here you can find the source of iterable(Iterator
Parameter | Description |
---|---|
iterator | a parameter |
T | a parameter |
public static <T> Iterable<T> iterable(Iterator<T> iterator)
//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; } }; } }