Android List Reverse reverse(List list, final int begin, final int end)

Here you can find the source of reverse(List list, final int begin, final int end)

Description

reverse

License

Open Source License

Declaration

public static <E> void reverse(List<E> list, final int begin,
            final int end) 

Method Source Code

//package com.java2s;
/**//from   ww  w. j  a  va2  s .com
 * RxDroid - A Medication Reminder
 * Copyright (C) 2011-2014 Joseph Lehner <joseph.c.lehner@gmail.com>
 *
 *
 * RxDroid is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. Additional terms apply (see LICENSE).
 *
 * RxDroid 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with RxDroid.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static <E> void reverse(List<E> list, final int begin,
            final int end) {
        if (end <= begin)
            throw new IllegalArgumentException("end <= begin");

        if (end - begin == 1)
            return;

        List<E> reversed = new ArrayList<E>(end - begin);

        for (int i = begin; i != end; ++i) {
            final int j = begin + (end - i - 1);
            reversed.add(list.get(j));
        }

        for (int i = 0; i != reversed.size(); ++i)
            list.set(begin + i, reversed.get(i));
    }
}

Related

  1. invertList(List list)
  2. reverse(List list)