Here you can find the source of iterable(final Iterator
Parameter | Description |
---|---|
NullPointerException | if list is null |
public static <T> Iterable<T> iterable(final Iterator<T> iter)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w .j ava 2 s. c om*/ * Mike Kucera (IBM Corporation) - initial API and implementation *******************************************************************************/ import java.util.Iterator; public class Main { /** * Creates an Iterable instance that just returns * the given Iterator from its iterator() method. * * This is useful for using an iterator in a foreach loop directly. * * e.g. * * for(Object o : iterable(list.listIterator())) { * // do something * } * * @throws NullPointerException if list is null */ public static <T> Iterable<T> iterable(final Iterator<T> iter) { if (iter == null) throw new NullPointerException("iter parameter is null"); //$NON-NLS-1$ return new Iterable<T>() { public Iterator<T> iterator() { return iter; } }; } }