Java ArrayList Remove removeLastValues(final ArrayList v, final int remove)

Here you can find the source of removeLastValues(final ArrayList v, final int remove)

Description

The Method removeLastValues(ArrayList, int) remove the last Values.

License

Apache License

Parameter

Parameter Description
T the generic type
v The Vector with the received Messages.
remove How much to remove.

Return

the list

Declaration

public static <T> List<T> removeLastValues(final ArrayList<T> v, final int remove) 

Method Source Code

//package com.java2s;
/**/* w  w w. jav a  2 s  . c  o m*/
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * The Method removeLastValues(ArrayList, int) remove the last Values.
     *
     * @param <T>
     *            the generic type
     * @param v
     *            The Vector with the received Messages.
     * @param remove
     *            How much to remove.
     * @return the list
     */
    public static <T> List<T> removeLastValues(final ArrayList<T> v, final int remove) {
        if (remove < v.size()) {
            final List<T> l = v.subList(remove, v.size());
            return l;
        }
        throw new IllegalArgumentException("You cannot remove "
                + "more element than in the ArrayList exists. \nSize from ArrayList:" + v.size() + "\n"
                + "Elements to be removed:" + remove + "\n The same ArrayList will be returned.");
    }
}

Related

  1. removeDuplicates(ArrayList a)
  2. removeDuplicateWithOrder(List arrayList)
  3. removeElementsFromIndexToEnd(ArrayList list, int index)
  4. removeExtraPunctuation(String line, int startChar, ArrayList indices)
  5. removeIndex(ArrayList arr, ArrayList idNames)
  6. removeNulls(ArrayList list)
  7. removeRepeatedElems(ArrayList list)