Java List Reverse reverse(final List a)

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

Description

Reverse order of elements in a list.

License

Open Source License

Parameter

Parameter Description
T the elements type
a a list of elements

Return

a list in reverse order

Declaration

private static <T> ArrayList<T> reverse(final List<T> a) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 LegSem./*from   w  w w .  j a v a  2 s.com*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     LegSem - initial API and implementation
 ******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Reverse order of elements in a list.
     * 
     * @param <T> the elements type
     * @param a a list of elements
     * @return a list in reverse order
     */
    private static <T> ArrayList<T> reverse(final List<T> a) {
        ArrayList<T> r = new ArrayList<T>();

        for (int i = a.size() - 1; i >= 0; i--) {
            r.add(a.get(i));
        }

        return r;
    }
}

Related

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