gpt4 book ai didi

java - 如何将 arrayList 存储到 java 中的数组中?

转载 作者:搜寻专家 更新时间:2023-10-31 08:10:27 28 4
gpt4 key购买 nike

java中如何将arrayList存储到数组中?

最佳答案

这取决于你想要什么:

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

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

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

但是如果您想要数组中的 items 列表,请执行以下操作之一:

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

引用:

关于java - 如何将 arrayList 存储到 java 中的数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244268/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com