increasing size of array

 

package quiz;

import java.util.*;

public class RotaionArray {

    public static void main(String[] args) {

        

    

    int A[]= {1,2,3,4,5,6,7,8,9,10};

    int B[]=new int[A.length*2];

        System.out.print(“B:”);

    for(int i=A.length-1,j=0;i>=0;i–,j++){

        B[i]=A[i];

      }

    A=B;

        B=null;

        for(int x:A)

        System.out.print(x+”,”);

        //first create another array with desire size

        //then copy element to new one

        //now reference the new one to old one and new one will be null            

    }

    

}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top