Here you can find the source of removeAt(T[] array, int index)
Parameter | Description |
---|---|
array | The array to remove an element from. |
index | The index of the element to remove. |
public static <T> T[] removeAt(T[] array, int index)
//package com.java2s; /* // ww w . j a v a 2 s . co m * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the file LICENSE.txt. It is also available * through the world-wide-web at http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to obtain it * through the world-wide-web, please send an email to magnos.software@gmail.com * so we can send you a copy immediately. If you use any of this software please * notify me via our website or email, your feedback is much appreciated. * * @copyright Copyright (c) 2011 Magnos Software (http://www.magnos.org) * @license http://opensource.org/licenses/osl-3.0.php * Open Software License (OSL 3.0) */ import java.util.Arrays; public class Main { /** * Removes the element at the index from the array and returns a new array. * * @param array * The array to remove an element from. * @param index * The index of the element to remove. * @return The reference to a new array without the element at the index. */ public static <T> T[] removeAt(T[] array, int index) { System.arraycopy(array, index + 1, array, index, array.length - index - 1); return Arrays.copyOf(array, array.length - 1); } }