Arrays.copyOfRange(array, start, end);Source:wal.wwutturi.com
Copy the specified range of the specified array into a new array in java.
example:
/**
* @author lautturi.com
* Java example: Shorten array in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
int[] numArray = { 11,4,12,7,55,8,12,8,13,55,12,7 };
int[] newArray = Arrays.copyOfRange(numArray, 2, 8);
System.out.println(Arrays.toString(newArray));
}
}
output:
[12, 7, 55, 8, 12, 8]