1import java.util.Arrays;
2
3class Main
4{
5 // Generic function to get sub-array of a non-primitive array
6 // between specified indices
7 public static<T> T[] subArray(T[] array, int beg, int end) {
8 return Arrays.copyOfRange(array, beg, end + 1);
9 }
10
11 public static void main(String[] args)
12 {
13 String[] arr = { "A", "B", "C", "D", "E", "F", "G", "H" };
14 int beg = 1, end = 4;
15
16 String[] subarray = subArray(arr, beg, end);
17 System.out.println(Arrays.toString(subarray));
18 }
19}
20