how to increase an regular array length in java?

Arrays in Java are of fixed size that is specified when they are declared. To increase the size of the array you have to create a new array with a larger size and copy all of the old values into the new array.

ex:

//declare an array at first
Object[] myStore= new Object[10];
//now if I almost use up all spaces of myStore, I can create a new one with double length myStore = Arrays.copyOf(myStore, myStore.length*2); //the original one will be garbage collected by jvm

 

posted @ 2014-09-16 16:20  zmiao  阅读(134)  评论(0编辑  收藏  举报