我怎样才能改变一个数组的长度? [英] How can I change the length of an array?

查看:184
本文介绍了我怎样才能改变一个数组的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我分配了一个项目,我有一个数组和用户将元素融入到这个数组将有长度的两倍,一旦它得到充分。我们不允许使用数组列表或任何在集合接口。我试图做的是使一个新的数组,一旦旧得满满的,然后我会过的值复制到新数组。问题是我不知道多少次,我将不得不作出一个新的数组,所以我想知道如何去解决这一点。

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

这篇关于我怎样才能改变一个数组的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆