Java Array arrayExclude(double[] src, int excludeIndex)

Here you can find the source of arrayExclude(double[] src, int excludeIndex)

Description

Excludes an element from a provided array and returns a copy without the element.

License

Open Source License

Parameter

Parameter Description
src Source array to exclude from
excludeIndex index to exclude from src

Return

(New) array without the element at index 'excludeIndex'

Declaration

public static double[] arrayExclude(double[] src, int excludeIndex) 

Method Source Code

//package com.java2s;
/**/*  ww  w. j  a  va 2 s .  c om*/
 * Copyright (C) 2014 Aniruddh Fichadia
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * If you use or enhance the code, please let me know using the provided author information or via
 * email Ani.Fichadia@gmail.com.
 */

public class Main {
    /**
     * Excludes an element from a provided array and returns a copy without the element.
     * 
     * @param src Source array to exclude from
     * @param excludeIndex index to exclude from src
     * 
     * @return (New) array without the element at index 'excludeIndex'
     */
    public static double[] arrayExclude(double[] src, int excludeIndex) {
        double[] temp = new double[src.length - 1];

        // Copy upto the element
        System.arraycopy(src, 0, temp, 0, excludeIndex);
        // Copy after the element
        System.arraycopy(src, excludeIndex + 1, temp, excludeIndex, src.length - excludeIndex - 1);

        return temp;
    }
}

Related

  1. array_equals(byte[] foo, byte bar[])
  2. array_int2float(int ai[])
  3. array_intAddLimit(int[] in, int value, int limit)
  4. arrayed(int arrays, String inner)
  5. arrayEndsWith(final byte[] array, final byte[] str)
  6. arrayFirstIndexOf(final T[] array, final T value)
  7. arrayFlatten(final int[][] arr)
  8. arrayGetCenter(byte[] array, int location, int length)
  9. arrayIsHave(String[] strs, String str)