This method is used to intercept and copy an existing array, and copy an array with a closed left range and an open right range. Copy an original array starting from the subscript from to the superscript to, and generate a new array and return it.
Note : From is included here, but to is not included, that is, [from, to).
For example:
importjava.util.Arrays;publicclassMain{publicstaticvoidmain(String[]args){int[]arr={1,2,3,4,5,6,7,8};System.out.println(Arrays.toString(arr ));//Copy the entire array int[]allArr=Arrays.copyOfRange(arr,0,8);StringallString=Arrays.toString(allArr);//Copy part of the array int[]partArr=Arrays.copyOfRange(arr,2 ,6);StringpartString=Arrays.toString(partArr);System.out.println(allString);System.out.println(partString);}}
The running results are as follows:
[1,2,3,4,5,6,7,8][1,2,3,4,5,6,7,8][3,4,5,6]