Example usage for java.util Arrays copyOfRange

List of usage examples for java.util Arrays copyOfRange

Introduction

In this page you can find the example usage for java.util Arrays copyOfRange.

Prototype

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

Source Link

Document

Copies the specified range of the specified array into a new array.

Usage

From source file:Main.java

public static void main(String[] args) {

    int[] arr1 = new int[] { 5, 60, 75 };

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

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

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

From source file:Main.java

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));
}

From source file:Main.java

public static void main(String[] args) {

    short[] arr1 = new short[] { 15, 10, 45 };

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

    // copying array arr1 to arr2 with range of index from 1 to 3
    Object arr2 = Arrays.copyOfRange(arr1, 1, 3);

    // cast arr2 as short in order to be printable
    short[] arr3 = (short[]) arr2;

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

From source file:Main.java

public static void main(String[] args) {

    float[] arr1 = new float[] { 10f, 30f, 50f };

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

    // copying array arr1 to arr2 with range of index from 1 to 4
    float[] arr2 = Arrays.copyOfRange(arr1, 1, 2);
    arr2[3] = 90f;//from   w w w .j ava2  s.c o m
    arr2[4] = 100f;

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

From source file:Main.java

public static void main(String[] args) {

    boolean[] arr1 = new boolean[] { true, false, false };

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

    // copying array arr1 to arr2 with range from index 1 to 4
    boolean[] arr2 = Arrays.copyOfRange(arr1, 1, 4);

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    byte[] arr1 = new byte[] { 5, 10, 25 };

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

    // copying array arr1 to arr2 with range from index 1 to 7
    byte[] arr2 = Arrays.copyOfRange(arr1, 1, 7);

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

From source file:ArrayReallocationDemo.java

public static void main(String[] args) {
    int[] data1 = new int[] { 1, 3, 5, 7, 9 };

    printArray(data1);/*from  w ww  .ja  v a  2 s  .  com*/
    int[] data2 = Arrays.copyOf(data1, 6);
    data2[5] = 11;
    printArray(data2);

    int[] data3 = Arrays.copyOfRange(data1, 2, 10);
    printArray(data3);
}

From source file:Main.java

public static void main(String[] args) {

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

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

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

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    char[] arr1 = new char[] { 'j', 'a', 'v' };

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

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

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

From source file:Main.java

public static void main(String[] args) {

    // intializing an array arr1
    double[] arr1 = new double[] { 1.5, 3.5, 7.5 };

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

    // copying array arr1 to arr2 with range of index from 1 to 4
    double[] arr2 = Arrays.copyOfRange(arr1, 1, 4);

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