arrays copyofrange 28 29 method in java

Solutions on MaxInterview for arrays copyofrange 28 29 method in java by the best coders in the world

showing results for - "arrays copyofrange 28 29 method in java"
Leon
22 Oct 2018
1// arrays copyOfRange() method in java example
2import java.util.Arrays;
3public class ArrayCopyOfRangeDemo 
4{
5   public static void main(String[] args) 
6   {
7      int[] arrNumber = { 66, 67, 68, 69, 70, 71, 72 };
8      System.out.println("Given array: ");
9      for(int a = 0; a < arrNumber.length; a++) 
10      {
11         System.out.println(arrNumber[a]); 
12      }
13      int[] copyNum = Arrays.copyOfRange(arrNumber, 2, 6);
14      System.out.println("----------------------");
15      System.out.println("Between range 2 and 6: ");
16      for(int a : copyNum)
17      {
18         System.out.print(a + " ");
19      }
20      System.out.println();
21   }
22}
Leah
24 Feb 2019
1// arrays copyofrange short data type example
2import java.util.Arrays;
3public class ArrayCopyShort
4{
5   public static void main(String[] args)
6   {
7      short[] arrShort1 = new short[] {14, 23, 41};
8      System.out.println("ARRAY COPY OF RANGE METHOD - SHORT DATA TYPE");
9      System.out.println("--------------------------------------------");
10      System.out.println("Given array : ");
11      for(int a = 0; a < arrShort1.length; a++)
12      {
13         System.out.println(arrShort1[a]);
14      }
15      // java copyofrange
16      short[] arrShort2 = Arrays.copyOfRange(arrShort1, 1, 3);
17      System.out.println("Copied array : ");
18      for(int a = 0; a < arrShort2.length; a++)
19      {
20         System.out.println(arrShort2[a]);
21      }
22   }
23}