Java Collection Tutorial - Java Arrays.copyOfRange(long[] original, int from, int to)








Syntax

Arrays.copyOfRange(long[] original, int from, int to) has the following syntax.

public static long[] copyOfRange(long[] original,   int from,   int to)

Example

In the following code shows how to use Arrays.copyOfRange(long[] original, int from, int to) method.

/* w  ww . j a v a 2 s.com*/

import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    long[] arr1 = new long[] {5, 60, 75};

    System.out.println(Arrays.toString(arr1));

    // copying array arr1 to arr2 with range of index from 2 to 5
    long[] arr2 = Arrays.copyOfRange(arr1, 2, 5);

    System.out.println(Arrays.toString(arr2));
  }
}

The code above generates the following result.