如何在java中将arrayList存储到数组中? [英] How to store arrayList into an array in java?

查看:52
本文介绍了如何在java中将arrayList存储到数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java中如何将arrayList存入数组?

How to store arrayList into an array in java?

推荐答案

这取决于你想要什么:

List<String> list = new ArrayList<String>();
// add items to the list

现在,如果您想将列表存储在数组中,您可以执行以下操作之一:

Now if you want to store the list in an array, you can do one of these:

Object[] arrOfObjects = new Object[]{list};
List<?>[] arrOfLists = new List<?>[]{list};

但是如果您希望在数组中列出 items,请执行以下操作之一:

But if you want the list items in an array, do one of these:

Object[] arrayOfObjects = list.toArray();
String[] arrayOfStrings = list.toArray(new String[list.size()]);

参考:

这篇关于如何在java中将arrayList存储到数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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