Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  

Array ---- Re-initialise



Share on Google+Share on Google+

Aghil krishna
Array ---- Re-initialise
1 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners

How can i re-initialise the initial capacity of an Array when it's exceed the old capacity ...?

View Answers

November 17, 2010 at 1:31 PM

Hello Friend,

Try the following code:

class ReinitializeArray{

public static int[] resizeArray(int[] arrayToResize,int newsize) {
    int[] newArray = new int[newsize];
    System.arraycopy(arrayToResize, 0,newArray, 0, arrayToResize.length);
    return newArray;
public static void main (String[] args) {
   int[] arr = {1,2};
   arr = (int[])resizeArray(arr,5);
   arr[2] = 3;
   arr[3] = 4;
   arr[4] = 5;
   for (int i=0; i<arr.length; i++)
   System.out.println (arr[i]);



Related Tutorials/Questions & Answers: