Java 数组改变大小 [英] Java arrays change size

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

问题描述

我需要更改数组的大小,但我不能简单地创建另一个 - 它需要相同的名称,以便我可以将其传递给方法.具体来说,我需要数组的项数是过去的两倍.这可以用一个数组来做吗?我可以将数据从数组 A 复制到数组 B,然后使用 A = B 使 A 引用与 B 相同的数据吗??

I need to change the size of an array, but I cannot simply create another - It needs the same name so I can pass it to a method. Specifically, I need the array to have twice as many terms as it used to. Is this possible to do with one array? Can I copy data from array A to array B, then make A reference the same data as B with A = B; ?

推荐答案

是的,您的数组变量可能引用相同类型但大小不同的数组.

Yes, your array variable may reference an array of the same type but different size.

为了在内部更改它,ArrayList 可能更易于使用.

For changing it internally, an ArrayList might be more easy to use.

这篇关于Java 数组改变大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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