如何将arrayList存储到Java中的数组中?
那取决于你想要什么:
List<String> list = new ArrayList<String>();
// add items to the list
现在,如果要将列表存储在数组中,则可以执行以下操作之一:
Object[] arrOfObjects = new Object[]{list};
List<?>[] arrOfLists = new List<?>[]{list};
但是,如果要将列表项放在数组中,请执行以下一项操作:
Object[] arrayOfObjects = list.toArray();
String[] arrayOfStrings = list.toArray(new String[list.size()]);
参考:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句