ArrayList 初始化等价于数组初始化 [英] ArrayList initialization equivalent to array initialization

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

问题描述

我知道你可以在实例化过程中初始化一个数组,如下所示:

I am aware that you can initialize an array during instantiation as follows:

String[] names = new String[] {"Ryan", "Julie", "Bob"};

有没有办法用 ArrayList 做同样的事情?还是我必须使用 array.add() 单独添加内容?

Is there a way to do the same thing with an ArrayList? Or must I add the contents individually with array.add()?

推荐答案

Arrays.asList 可以在这里提供帮助:

Arrays.asList can help here:

new ArrayList<Integer>(Arrays.asList(1,2,3,5,8,13,21));

这篇关于ArrayList 初始化等价于数组初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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