Java Array Remove removeIndex(T[] array, int index)

Here you can find the source of removeIndex(T[] array, int index)

Description

Returns a copy of the given array, with the element at the given index removed.

License

Open Source License

Declaration

public static <T> T[] removeIndex(T[] array, int index) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//www  .ja va  2  s .  c o  m
     * Returns a copy of the given array, with the element at the given index removed.
     * <p>
     * This version moves the last array element to the removed element's position.
     */
    public static <T> T[] removeIndex(T[] array, int index) {
        return removeIndex(array, index, false);
    }

    /**
     * Returns a copy of the given array, with the element at the given index removed.
     */
    public static <T> T[] removeIndex(T[] array, int index,
            boolean keepOrder) {

        if (index != array.length - 1) {
            if (keepOrder) {
                System.arraycopy(array, index + 1, array, index,
                        array.length - 2 - index);
            } else {
                array[index] = array[array.length - 1];
            }
        }

        return Arrays.copyOf(array, array.length - 1);
    }
}

Related

  1. removeFrom(double[] source, int idx)
  2. removeFromArray(String remove, String array[])
  3. removeFromArray(String[] oldArray, String stringToRemove)
  4. removeId(byte[] in, Integer id)
  5. removeIndex(String[] args, int index)
  6. removeLast(byte[] target, int end)
  7. removeLowScore(int[] array)
  8. removeMethodsOption(String[] args)
  9. removeNaN(double[] x1)