我怎样才能改变一个数组的长度?

编程入门 行业动态 更新时间:2024-10-10 10:33:18
本文介绍了我怎样才能改变一个数组的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

我怎样才能改变一个数组的长度?

本文发布于:2023-11-29 13:27:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   长度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!