Java array substring
How can I create/instantiate an array to be equal to the substring of another array, where the size of the substring is unknown: int n; //some number derived somewhere else String[] grp = elements[i] to elements[i+n]; Use Arrays.copyOfRange : public static <T> T[] copyOfRange(T[] original, int from, int to) Copies the specified range of the specified array into a new array. The initial index of the range ( from ) must lie between zero and original.length , inclusive. The value at original[from] is placed into the initial element of the copy (unless from == original.length or from == to ).