您的位置:首页 > 编程语言 > Java开发

how to increase an regular array length in java?

2014-09-16 16:20 351 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: