Answers for "array slice java"

0

slicing array in java

import java.util.Arrays;
public class SlicingAnArray {
   public static void main(String args[]){
      int intArray[] = {12, 14, 58, 225, 56, 96 , 3, 45, 8 };
      intArray = Arrays.copyOfRange(intArray, 3, 7);
      System.out.println(Arrays.toString(intArray));
   }
}
Posted by: Guest on February-21-2021
0

slice array 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 June-23-2021
0

take a peice from array java

import java.util.IntStream;
// for java 8 and 8+
IntStream.range(start, end).map(x -> arr[x]).toArray();
Posted by: Guest on May-07-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language