• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 19, 2022 |830 Views

Java program to slice an array

Description
Discussion

In this video, we will write a Java program to get slice of a Primitive Array.

We will be using 2 methods to get the slice of an array: 
1) Using Naive Method 
2) Using .copyOfRange() method. 

Method 1: In this method, we declare a new integer array of the size of the slice and keep inserting elements by iterating on the original array in the slicing range. The resultant array is our required array. 

Method 2: In this method, we use the .copyOfRange() method of Arrays class to create a copy array for given start to end index. This method will return a new copy array, this array will be our required slicing of the original array. 

How to get slice of a Primitive Array in Java:
https://www.geeksforgeeks.org/how-to-get-slice-of-a-primitive-array-in-java/