Java List Reverse iterateReverse(final List elements)

Here you can find the source of iterateReverse(final List elements)

Description

iterate Reverse

License

Apache License

Declaration

public static <T> Iterable<T> iterateReverse(final List<T> elements) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

import java.util.Iterator;

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

public class Main {
    public static <T> Iterable<T> iterateReverse(final List<T> elements) {
        return new Iterable<T>() {

            @Override//from w  ww .j av a 2  s . com
            public Iterator<T> iterator() {
                return new Iterator<T>() {

                    ListIterator<T> it = elements.listIterator(elements.size());

                    @Override
                    public boolean hasNext() {
                        return it.hasPrevious();
                    }

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

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

        };
    }

    @SuppressWarnings("rawtypes")
    public static int size(Iterable<?> i) {
        if (i instanceof Collection) {
            return ((Collection) i).size();
        }
        int size = 0;
        for (@SuppressWarnings("unused")
        Object o : i) {
            size++;
        }
        return size;
    }
}

Related

  1. compareVersions(String version1, String version2)
  2. createReversedList(List inputList)
  3. firstElementOf(List list, int reverseIndexPosition)
  4. formatToIp(final List shortList, final boolean reverseOrder)
  5. getReversedListIterable(final List inList)
  6. listToArrowSep(List strings, String highlightFirst, String highlightSecond, boolean reversed)
  7. reverse(Collection list)
  8. reverse(final List list)
  9. reverse(final List a)