We can also use the copyOfRange() method defined in Java Arrays class to copy arrays. For example,
Output for the above code block will be
In the above example, notice the line,
Here, we can see that we are creating the destination1 array and copying the source array to it at the same time. We are not creating the destination1 array before calling the copyOfRange() method.