所以我分配了一个项目,我有一个数组和用户将元素融入到这个数组将有长度的两倍,一旦它得到充分。我们不允许使用数组列表或任何在集合接口。我试图做的是使一个新的数组,一旦旧得满满的,然后我会过的值复制到新数组。问题是我不知道多少次,我将不得不作出一个新的数组,所以我想知道如何去解决这一点。
So I am assigned with a project where I have an array and as the user puts elements into this array it will have to double in length once it gets full. We are not permitted to use array lists or anything in the collections interface. What I was trying to do was to make a new array once the old one was full, and then I would copy the values over to the new array. The problem is I don't know how many times I will have to make a new array, so I was wondering how to go about solving this.
推荐答案数组长度固定。如果你想有一个数据结构,具有可变长度使用ArrayList
Arrays are fixed length. If you want a data structure that has variable length use an ArrayList
更多推荐
我怎样才能改变一个数组的长度?
发布评论