array slice java
int[] newArray = Arrays.copyOfRange(oldArray, startIndex, endIndex);
array slice java
int[] newArray = Arrays.copyOfRange(oldArray, startIndex, endIndex);
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));
}
}
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)
take a peice from array java
import java.util.IntStream;
// for java 8 and 8+
IntStream.range(start, end).map(x -> arr[x]).toArray();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us