Here you can find the source of reverse(List
Parameter | Description |
---|---|
src | a parameter |
dst | a parameter |
public static <T> void reverse(List<T> src, List<T> dst)
//package com.java2s; /*//ww w . j av a2 s . com * Copyright (C) 2014 Riccardo Traverso * * This file is part of JavaUtils * Website: https://github.com/rtraverso86/JavaUtils * * JavaUtils is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JavaUtils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.List; import java.util.ListIterator; public class Main { /** * It copies list src onto dst in reversed order, eventually clearing the * destination list dst beforehand. * * @param src * @param dst */ public static <T> void reverse(List<T> src, List<T> dst) { if (!dst.isEmpty()) dst.clear(); ListIterator<T> lstIt = src.listIterator(src.size()); while (lstIt.hasPrevious()) { dst.add(lstIt.previous()); } } }