Java List Reverse reverse(final List list)

Here you can find the source of reverse(final List list)

Description

reverse

License

Open Source License

Declaration

public static <E> Iterable<E> reverse(final List<E> list) 

Method Source Code

//package com.java2s;
/*//from  w w w.j  a  v a 2 s  . c  o m
 * Copyright (c) 2012-2014, Parallel Universe Software Co. All rights reserved.
 * 
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *  
 *   or (per the licensee's choosing)
 *  
 * under the terms of the GNU Lesser General Public License version 3.0
 * as published by the Free Software Foundation.
 */

import java.util.Deque;

import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class Main {
    public static <E> Iterable<E> reverse(final Deque<E> deque) {
        return new Iterable<E>() {
            @Override
            public Iterator<E> iterator() {
                return deque.descendingIterator();
            }
        };
    }

    public static <E> Iterable<E> reverse(final List<E> list) {
        return new Iterable<E>() {
            @Override
            public Iterator<E> iterator() {
                final ListIterator<E> it = list.listIterator(list.size());
                return new Iterator<E>() {
                    @Override
                    public boolean hasNext() {
                        return it.hasPrevious();
                    }

                    @Override
                    public E next() {
                        return it.previous();
                    }

                    @Override
                    public void remove() {
                        it.remove();
                    }
                };
            }
        };
    }
}

Related

  1. formatToIp(final List shortList, final boolean reverseOrder)
  2. getReversedListIterable(final List inList)
  3. iterateReverse(final List elements)
  4. listToArrowSep(List strings, String highlightFirst, String highlightSecond, boolean reversed)
  5. reverse(Collection list)
  6. reverse(final List a)
  7. reverse(final List l)
  8. reverse(final List list)
  9. reverse(final List list)