Answers for "slice array java"

9

array slice java

int[] newArray = Arrays.copyOfRange(oldArray, startIndex, endIndex);
Posted by: Guest on July-06-2020
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

Browse Popular Code Answers by Language