Java tutorial
//package com.java2s; import java.lang.reflect.Array; 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); 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, int offset, int length) { int len2 = buffer.length - length; double[] temp = new double[len2]; System.arraycopy(buffer, 0, temp, 0, offset); System.arraycopy(buffer, offset + length, temp, offset, len2 - offset); return temp; } /** * Removes sub-array from <code>boolean</code> array. */ public static boolean[] remove(boolean[] buffer, int offset, int length) { int len2 = buffer.length - length; boolean[] temp = new boolean[len2]; System.arraycopy(buffer, 0, temp, 0, offset); System.arraycopy(buffer, offset + length, temp, offset, len2 - offset); return temp; } }