Here you can find the source of removeLastValues(final ArrayList
Parameter | Description |
---|---|
T | the generic type |
v | The Vector with the received Messages. |
remove | How much to remove. |
public static <T> List<T> removeLastValues(final ArrayList<T> v, final int remove)
//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."); } }