Android List Reverse invertList(List list)

Here you can find the source of invertList(List list)

Description

Invert / Reverse the provided List .

Parameter

Parameter Description
V < >
list - of List type.

Return

- an new inverted copy of the provided list.

Declaration

public static <V> List<V> invertList(List<V> list) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*  w w w.  j  av a2s. c  o m*/
     * Invert / Reverse the provided {@link List}.
     * <br>
     * Returns a new inverted copy for the list.
     * 
     * @param <V>
     * @param list - of {@link List} type.
     * @return {@link List} - an new inverted copy of the provided list. 
     */
    public static <V> List<V> invertList(List<V> list) {
        if (isEmpty(list)) {
            return list;
        }

        List<V> invertList = new ArrayList<V>(list.size());
        for (int i = list.size() - 1; i >= 0; i--) {
            invertList.add(list.get(i));
        }
        return invertList;
    }

    /**
     * Returns true if list is null or its size is 0
     * 
     * <pre>
     * isEmpty(null)   =   true;
     * isEmpty({})     =   true;
     * isEmpty({1})    =   false;
     * </pre>
     * 
     * @param <V>
     * @param list - of {@link List} type.
     * @return boolean - true if list is null or empty, else false.
     */
    public static <V> boolean isEmpty(List<V> list) {
        return (list == null || list.size() == 0);
    }
}

Related

  1. reverse(List list, final int begin, final int end)
  2. reverse(List list)