@Test public void testRemoveElementAtLastIndex() { String[] data = new String[] { "a", "b", "c", "d", "e" }; int index = 4; String[] result = Arrays.removeElementAtIndex(data, index); Assert.assertEquals(data[0], result[0]); Assert.assertEquals(data[1], result[1]); Assert.assertEquals(data[2], result[2]); Assert.assertEquals(data[3], result[3]); Assert.assertEquals(4, result.length); }
public static <ELEMENTTYPE> ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index) { Assert.isTrue(array.length > 0, "Cannot remove an element from an already empty array."); ELEMENTTYPE[] result = java.util.Arrays.copyOf(array, array.length - 1); if (result.length > 0 && array.length + 1 != index && index != result.length) System.arraycopy(array, index + 1, result, index, array.length - (array.length - index)); return result; }
Arrays { public static <ELEMENTTYPE> ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index) { Assert.isTrue(array.length > 0, "Cannot remove an element from an already empty array."); ELEMENTTYPE[] result = java.util.Arrays.copyOf(array, array.length - 1); if (result.length > 0 && array.length + 1 != index && index != result.length) System.arraycopy(array, index + 1, result, index, array.length - (array.length - index)); return result; } }
Arrays { public static <ELEMENTTYPE> ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index) { Assert.isTrue(array.length > 0, "Cannot remove an element from an already empty array."); ELEMENTTYPE[] result = java.util.Arrays.copyOf(array, array.length - 1); if (result.length > 0 && array.length + 1 != index && index != result.length) System.arraycopy(array, index + 1, result, index, array.length - (array.length - index)); return result; }  }
Arrays { public static <ELEMENTTYPE> ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index) { Assert.isTrue(array.length > 0, "Cannot remove an element from an already empty array."); ELEMENTTYPE[] result = java.util.Arrays.copyOf(array, array.length - 1); if (result.length > 0 && array.length + 1 != index && index != result.length) System.arraycopy(array, index + 1, result, index, array.length - (array.length - index)); return result; }  @SafeVarargs static ELEMENTTYPE[] append(ELEMENTTYPE[] array, ELEMENTTYPE... elements); @SafeVarargs static ELEMENTTYPE[] prepend(ELEMENTTYPE[] array, ELEMENTTYPE... elements); static ELEMENTTYPE[] copy(ELEMENTTYPE[] source, ELEMENTTYPE[] target); static ELEMENTTYPE[] shiftLeft(ELEMENTTYPE[] source, ELEMENTTYPE[] target); static boolean contains(ELEMENTTYPE[] array, ELEMENTTYPE value); static int indexOf(ELEMENTTYPE[] array, ELEMENTTYPE value); static ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index); }
Arrays { public static <ELEMENTTYPE> ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index) { Assert.isTrue(array.length > 0, "Cannot remove an element from an already empty array."); ELEMENTTYPE[] result = java.util.Arrays.copyOf(array, array.length - 1); if (result.length > 0 && array.length + 1 != index && index != result.length) System.arraycopy(array, index + 1, result, index, array.length - (array.length - index)); return result; }  @SafeVarargs static ELEMENTTYPE[] append(ELEMENTTYPE[] array, ELEMENTTYPE... elements); @SafeVarargs static ELEMENTTYPE[] prepend(ELEMENTTYPE[] array, ELEMENTTYPE... elements); static ELEMENTTYPE[] copy(ELEMENTTYPE[] source, ELEMENTTYPE[] target); static ELEMENTTYPE[] shiftLeft(ELEMENTTYPE[] source, ELEMENTTYPE[] target); static boolean contains(ELEMENTTYPE[] array, ELEMENTTYPE value); static int indexOf(ELEMENTTYPE[] array, ELEMENTTYPE value); static ELEMENTTYPE[] removeElementAtIndex(ELEMENTTYPE[] array, int index);  }