Java List Reverse addReverse(List list, List append)

Here you can find the source of addReverse(List list, List append)

Description

Adds the contents of one list to the other in reverse order.

License

Apache License

Parameter

Parameter Description
list The list to append to.
append Contains the values to append to the list.

Return

The same list.

Declaration

@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<?> addReverse(List list, List append) 

Method Source Code


//package com.java2s;
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *

import java.util.*;

public class Main {
    /**//from www.  ja v a 2  s. c om
     * Adds the contents of one list to the other in reverse order.
     * <p>
     * i.e. add values from 2nd list from end-to-start order to the end of the 1st list.
     *
     * @param list The list to append to.
     * @param append Contains the values to append to the list.
     * @return The same list.
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List<?> addReverse(List list, List append) {
        for (ListIterator i = append.listIterator(append.size()); i.hasPrevious();)
            list.add(i.previous());
        return list;
    }

    /**
     * Adds the contents of the array to the list in reverse order.
     * <p>
     * i.e. add values from the array from end-to-start order to the end of the list.
     *
     * @param list The list to append to.
     * @param append Contains the values to append to the list.
     * @return The same list.
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List<?> addReverse(List list, Object[] append) {
        for (int i = append.length - 1; i >= 0; i--)
            list.add(append[i]);
        return list;
    }
}

Related

  1. compareVersions(List list1, List list2)
  2. compareVersions(List version1, List version2)
  3. compareVersions(String version1, String version2)
  4. createReversedList(List inputList)