删除子

欢马劈雪     最近更新时间:2020-01-02 10:19:05

522
删除子数组。

// Copyright (c) 2003-present, Jodd Team (jodd.org). All Rights Reserved.

import java.lang.reflect.Array;

import static jodd.util.StringPool.NULL;

/* 
 来自 
*时代Java - nowjava.com*/

public class Main{

    /**

     * Removes sub-array.

     */

    public static <T> T[] remove(T[] buffer, int offset, int length) {

        Class<T> componentType = (Class<T>) buffer.getClass()

                .getComponentType();

        return remove(buffer, offset, length, componentType);

    }

    /**

     * Removes sub-array.

     */

    @SuppressWarnings({ "unchecked" })

    public static <T> T[] remove(T[] buffer, int offset, int length,

            Class<T> componentType) {

        int len2 = buffer.length - length;

        T[] temp = (T[]) Array.newInstance(componentType, len2);/*时   代     Java  公  众  号 - nowjava.com 提供*/

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>String</code> array.

     */

    public static String[] remove(String[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        String temp[] = new String[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>byte</code> array.

     */

    public static byte[] remove(byte[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        byte temp[] = new byte[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>char</code> array.

     */

    public static char[] remove(char[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        char temp[] = new char[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>short</code> array.

     */

    public static short[] remove(short[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        short temp[] = new short[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>int</code> array.

     */

    public static int[] remove(int[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        int temp[] = new int[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>long</code> array.

     */

    public static long[] remove(long[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        long temp[] = new long[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>float</code> array.

     */

    public static float[] remove(float[] buffer, int offset, int length) {

        int len2 = buffer.length - length;

        float temp[] = new float[len2];

        System.arraycopy(buffer, 0, temp, 0, offset);

        System.arraycopy(buffer, offset + length, temp, offset, len2

                - offset);

        return temp;

    }

    /**

     * Removes sub-array from <code>double</code> array.

     */

    public static double[] remove(double[] buffer, 
展开阅读全文