Java List Remove removeAfter(List children, int index)

Here you can find the source of removeAfter(List children, int index)

Description

Removes all elements after the given index

License

Open Source License

Parameter

Parameter Description
children a parameter
index a parameter

Declaration

public static void removeAfter(List<?> children, int index) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  w w.java  2 s . c o m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.List;

public class Main {
    /**
     * Removes all elements after the given index
     * 
     * @param children
     * @param index
     */
    public static void removeAfter(List<?> children, int index) {
        while (children.size() > index + 1) {
            children.remove(children.size() - 1);
        }
    }
}

Related

  1. remove(List list, int index, T defaultValue)
  2. remove(List list, int position)
  3. remove(List list, T remove)
  4. remove(List list, T value)
  5. remove(Object o, List oldList)
  6. removeAll(List list, Object[] elements)
  7. removeAll(List list, List objects)
  8. removeAll(List idxs, List values)
  9. removeAll(List strings, String string)