Java Utililty Methods List Reverse

List of utility methods to do List Reverse

Description

The list of methods to do List Reverse are organized into topic(s).

Method

ListreverseCopy(List original)
Returns a reversed shallow copy of the given list.
List<E> result = new ArrayList<E>(original.size());
if (original instanceof RandomAccess) {
    for (int i = original.size() - 1; i >= 0; i--) {
        result.add(original.get(i));
} else {
    ListIterator<E> it = original.listIterator(original.size());
    while (it.hasPrevious()) {
...
Iterablereversed(final List list)
reversed
return new Iterable<T>() {
    public Iterator<T> iterator() {
        return new Iterator<T>() {
            final ListIterator<T> it = list.listIterator(list.size());
            public boolean hasNext() {
                return it.hasPrevious();
            public T next() {
...
Listreversed(List l)
A reversed copy of the given list
List<T> copy = new ArrayList<T>(l);
Collections.reverse(copy);
return copy;
Iterablereversed(List list)
reversed
return () -> {
    ListIterator<T> li = list.listIterator(list.size());
    return new Iterator<T>() {
        @Override
        public boolean hasNext() {
            return li.hasPrevious();
        @Override
...
voidreversedCopy(List src, List dest)
reversed Copy
dest.clear();
for (T e : src) {
    dest.add(0, e);
IterablereverseIterable(final List list)
Allows a foreach loop to iterate backwards over a list from the end to the start.
return iterable(reverseIterator(list));
IteratorreverseIterator(final List list)
Returns an iterator that iterates backwards over the given 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"); 
};
IteratorreverseIterator(List list)
reverse Iterator
final ListIterator<T> listIterator = list.listIterator(list.size());
return new Iterator<T>() {
    @Override
    public boolean hasNext() {
        return listIterator.hasPrevious();
    @Override
    public T next() {
...
IterablereverseIterator(ListIterator iterator)
reverse Iterator
return () -> new Iterator<T>() {
    @Override
    public boolean hasNext() {
        return iterator.hasPrevious();
    @Override
    public T next() {
        return iterator.previous();
...
IterablereverseList(final List list)
Reverses the given list for iteration.
return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
        final ListIterator<T> li = list.listIterator(list.size());
        return new Iterator<T>() {
            @Override
            public boolean hasNext() {
                return li.hasPrevious();
...