Java Array Copy arrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove)

Here you can find the source of arrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove)

Description

array Copy With Removal

License

Open Source License

Declaration

public static void arrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2000, 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:/*w w  w .  j  a va 2  s .  c om*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    public static void arrayCopyWithRemoval(Object[] src, Object[] dst, int idxToRemove) {
        if (src == null || dst == null || src.length - 1 != dst.length || idxToRemove < 0
                || idxToRemove >= src.length) {
            throw new IllegalArgumentException();
        }

        if (idxToRemove == 0) {
            System.arraycopy(src, 1, dst, 0, src.length - 1);
        } else if (idxToRemove == src.length - 1) {
            System.arraycopy(src, 0, dst, 0, src.length - 1);
        } else {
            System.arraycopy(src, 0, dst, 0, idxToRemove);
            System.arraycopy(src, idxToRemove + 1, dst, idxToRemove, src.length - idxToRemove - 1);
        }
    }
}

Related

  1. arraycopy(T[] src, int srcPos, T[] dst, int len)
  2. arrayCopy(T[] x)
  3. arrayCopyAndAddEntry(T[] base, T extra)
  4. arraycopyAndInsertInt(final int[] src, final int idx, final int value)
  5. arrayCopyToNull(T[] source, int sourceOffset, T[] destination, int destinationOffset)
  6. Arrays_copyOf(int[] pos, int length)
  7. copy(byte[] bytes)
  8. copy(byte[] data, int from)
  9. copy(double[][] a)