Java List Reverse reverse(List src, List dst)

Here you can find the source of reverse(List src, List dst)

Description

It copies list src onto dst in reversed order, eventually clearing the destination list dst beforehand.

License

Open Source License

Parameter

Parameter Description
src a parameter
dst a parameter

Declaration

public static <T> void reverse(List<T> src, List<T> dst) 

Method Source Code

//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());
        }
    }
}

Related

  1. reverse(List list)
  2. reverse(List list)
  3. reverse(List list)
  4. reverse(List list)
  5. reverse(List list)
  6. reverse(List xs)
  7. reverse(List l)
  8. reverseCopy(Iterable list)
  9. reverseCopy(List list)