Answers for "how to get a section of an array in java"

0

how to get a section of an array in java

//index   0   1   2   3   4
int[] arr = {10, 20, 30, 40, 50};
Arrays.copyOfRange(arr, 0, 2);          // returns {10, 20}
Arrays.copyOfRange(arr, 1, 4);          // returns {20, 30, 40}
Arrays.copyOfRange(arr, 2, arr.length); // returns {30, 40, 50} (length = 5)
Posted by: Guest on March-22-2021

Code answers related to "how to get a section of an array in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language