如何ArrayList的存储到Java中的数组? [英] How to store arrayList into an array in java?
本文介绍了如何ArrayList的存储到Java中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何ArrayList的存储到Java中的数组?
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};
但是,如果你想在一个数组列表中的项目的,执行下列操作之一:
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()]);
参考:
这篇关于如何ArrayList的存储到Java中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文