Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

about arrays

  Asked By: Kaua    Date: May 20    Category: Java    Views: 623
  

Is there any way to resize an array during execution?

In vb this write redim preserve tom(5)

For exemple i declare at init :
myArray=new String[10];
and in another function i would like to preserve the 10 myArray contents and
resize myArray with higher value(String[30])

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Barabas Cohen     Answered On: May 20

public static String[] resizeArray(String[] array, int newSize){
if(newSize<array.length) return array;
String newArray[] = new String[newSize];
for(int i=0; i<array.length; i++){
newArray[i] = array[i];
}
return newArray;
}

myArray = resizeArray(myArray, 30);

 
Answer #2    Answered By: Stefan Thompson     Answered On: May 20

Yes, this preserve all existing data.
My first applet is nearly finished.

 
Didn't find what you were looking for? Find more on about arrays Or get search suggestion and latest updates.




Tagged: