Java Program to copy range of elements from an array

Published on July 4, 2015 by Senthil Kumar

Filed under Java

Last modified July 4, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 8622 times

The Java’s Arrays class provides a static function called Arrays.copyOfRange that helps the developers to copy a range of elements from one array to another.

How to Copy range of elements from an array in Java ?

Below is an example that demonstrates the copying of the range of objects from one array to another using Arrays.copyOfRange.

package com.abundantcode;
import java.util.Arrays;
import java.util.List;
public class Main {

    public static void main(String[] args)
        String[] input = {"Java", "", "MCA Lab Programs", "B.E Java Lab Programs", "BCA Java Programs"};

        System.out.println("Source Array");
        for(String item:input)
        String[] outPutArray = Arrays.copyOfRange(input, 1, 3);

        System.out.println("Destination Array");
        for(String item:outPutArray)




Source Array



MCA Lab Programs

B.E Java Lab Programs

BCA Java Programs

Destination Array


MCA Lab Programs


Leave a Comment


You might be Interested in these Posts

How to hide virtual keyboard in android using Java?

There are times when you want to hide the virtual keyboard in android. You can easily do that using ...

Java - How to use Packages to organize code ?

Problem Statement You need to use packages in java to organize your code. Solution Your Java prog...

Java - How to accept input from Keyboard ?

Problem Statement You need to accpet user input from the keyboard from your java program and displa...