Java Arrays copyOfRange方法针对Short类型


Java Arrays copyOfRange方法针对Short类型

package com.codingdict;

import java.util.Arrays;

public class ArrayDemo {
   public static void main(String[] args) {

      // intializing an array arr1
      Short arr1[] = new Short[]{15, 10, 45};

      // printing the array
      System.out.println("Printing 1st array:");
      for (int i = 0; i < arr1.length; i++) {
         System.out.println(arr1[i]);
      }

      // copying array arr1 to arr2 as Number with range of index from 1 to 3
      Number[] arr2 = Arrays.copyOfRange(arr1, 1, 3, Number[].class);

      // printing the array arr2, which is a Number array
      System.out.println("Printing new array:");
      for (int i = 0; i < arr2.length; i++) {
         System.out.println(arr2[i]);
      }
   }
}