Pages

Thursday, 2 January 2020

Difference between copyOf and copyOfRange methods

// Program on copyOf and copyOfRange methods
import java.util.Arrays;
public class cp
{
public static void main(String args[])
    {
        int a[] = {2, 8, 6, 1, 4, 3};
        int n = a.length;
        for (int i=0; i<n; i++)
            System.out.print(a[i]+" ");
   
    System.out.println();
        int[] c = Arrays.copyOf(a,5);
        for (int i=0; i<c.length; i++)
            System.out.println(a[i]+" ");
   
    System.out.println();   
    int[] d = Arrays.copyOfRange(a,0, 3);
        for (int i=0; i<d.length; i++)
            System.out.println(a[i]+" ");
          
 }
}        
   
output:

No comments:

Post a Comment

Constructors & Destructors in c++

  Constructors :  A Constructor is a special member function, which is used to initialize the objects of its class. The Constructor is invok...