Answers for "java sub array"

0

java subarray

import java.util.Arrays;
 
class Main
{
    // Generic function to get sub-array of a non-primitive array
    // between specified indices
    public static<T> T[] subArray(T[] array, int beg, int end) {
        return Arrays.copyOfRange(array, beg, end + 1);
    }
 
    public static void main(String[] args)
    {
        String[] arr = { "A", "B", "C", "D", "E", "F", "G", "H" };
        int beg = 1, end = 4;
 
        String[] subarray = subArray(arr, beg, end);
        System.out.println(Arrays.toString(subarray));
    }
}
Posted by: Guest on October-12-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language