Here you can find the source of reverseIterator(final List
Parameter | Description |
---|---|
NullPointerException | if list is null |
public static <T> Iterator<T> reverseIterator(final List<T> list)
//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 ww w. j av a2 s. c o m * Mike Kucera (IBM Corporation) - initial API and implementation *******************************************************************************/ import java.util.Iterator; import java.util.List; import java.util.ListIterator; public class Main { /** * Returns an iterator that iterates backwards over the given list. * The remove() method is not implemented and will throw UnsupportedOperationException. * The returned iterator does not support the remove() method. * * @throws NullPointerException if list is null */ public static <T> Iterator<T> reverseIterator(final List<T> list) { return new Iterator<T>() { ListIterator<T> iterator = list.listIterator(list.size()); public boolean hasNext() { return iterator.hasPrevious(); } public T next() { return iterator.previous(); } public void remove() { throw new UnsupportedOperationException("remove() not supported"); //$NON-NLS-1$ } }; } }