Here you can find the source of reverse(final List
Parameter | Description |
---|---|
T | the elements type |
a | a list of elements |
private static <T> ArrayList<T> reverse(final List<T> a)
//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; } }