Java Utililty Methods List Reverse

List of utility methods to do List Reverse

Description

The list of methods to do List Reverse are organized into topic(s).

Method

ListreverseList(List list)
reverse List
if (list == null || list.size() == 0) {
    return list;
int count = list.size() - 1;
Object obj = null;
for (int i = 0; i <= count / 2; i++) {
    obj = list.get(i);
    list.set(i, list.get(count - i));
...
ListreverseList(List list)
reverse List
List<T> theReturn = new ArrayList<T>();
int size = list.size();
for (int i = size - 1; i >= 0; i--) {
    T item = list.get(i);
    if (item != null) {
        theReturn.add(item);
return theReturn;
ListreverseList(List list, boolean shallowCopy)
Reverse list.
if (shallowCopy) {
    reverseListShallowCopy(list);
} else {
    List<T> list1 = new ArrayList<T>();
    for (int i = list.size() - 1; i >= 0; i--) {
        list1.add(list.get(i));
    return list1;
...
ListreverseList2(List list)
reverse List
List<T> revList = new ArrayList<T>();
for (Iterator<T> iterator = list.iterator(); iterator.hasNext();) {
    T n = iterator.next();
    revList.add(0, n);
return revList;
voidreverseListShallowCopy(List list)
Reverse list shallow copy.
Collections.reverse(list);
ListreverseOrder(List list)
The same list that has come in as a parameter is returned.
Collections.sort(list, Collections.reverseOrder());
return list;
StackreversePath(List pathParts)
Reverse path and return as a stack.
Stack<String> pathStack = new Stack<String>();
if (pathParts != null) {
    for (int i = pathParts.size() - 1; i >= 0; i--) {
        pathStack.push(pathParts.get(i));
return pathStack;
int[]reversePermutation(final List permutation)
Return the reverse permutation b of a permutation a of the numbers [0..n-1].
final int n = permutation.size();
final int[] array = new int[n];
for (int i = 0; i < n; i++) {
    array[i] = permutation.get(i);
return reversePermutation(array);
T[]reversePermutation(T[] arr, List p)
reverse Permutation
T[] arr_new = arr.clone();
for (int i = 0; i < arr.length; i++) {
    arr_new[i] = arr[p.get(i)];
return arr_new;
voidreverseSort(final List lines)
reverse Sort
Collections.sort(lines, REVERSE_ORDER);