我有一个ArrayList对象充满了一些ArrayList对象。一些条目是null并且我想只将的值不为空ArrayLists中的单个ArrayList。我在谈论下面的事情。从一些其他数组列表的列表中填充数组列表。
{null,[p1,p2,p3],[p2,p5,p6],[p4]}
而最终需要的输出是这样的。
[p1,p2,p3,p2,p5,p6,p4]
ArrayList中的ArrayList对象对象从hash map object
创建。我的代码段如下。但是它有什么问题。
Collection<ArrayList<MyProduct>> tmp = new ArrayList<ArrayList<MyProduct>>();
tmp= orderAdap.values();
ArrayList<MyProduct> flattenList = new ArrayList<MyProduct>();
for(ArrayList<MyProduct> list : tmp){
for(MyProduct i : list)
if(i!=null){
lstStyle.add(i);
}
}
那么有人可以帮助我。谢谢!!!!!
“但它有什么问题......”请更具体一些。你是否试图将项目添加到'flattenList'? –
最后想添加到ArrayList。 –
请告诉我们,他输出的是什么情况,是否有错误被抛出? –