在java中arraylist_在Java中将ArrayList添加到另一个ArrayList
我有以下Java代碼,其中我試圖將ArrayList復(fù)制到另一個(gè)ArrayList。
ArrayList nodes = new ArrayList();
ArrayList NodeList=new ArrayList();
ArrayList list=new ArrayList();
for(int i=0;i
Node childNode = PropertyNode.item(i);
NodeList Children = childNode.getChildNodes();
if(Children!=null){
nodes.clear();
nodes.add("PropertyStart");
nodes.add(Children.item(3).getTextContent());
nodes.add(Children.item(7).getTextContent());
nodes.add(Children.item(9).getTextContent());
nodes.add(Children.item(11).getTextContent());
nodes.add(Children.item(13).getTextContent());
nodes.add("PropertyEnd");
}
NodeList.addAll(nodes);
list.add(NodeList);
}
我希望“列表”數(shù)組采用以下格式:
[[PropertyStart,a,b,c,PropertyEnd],[PropertyStart,d,e,f,PropertyEnd],[PropertyStart,......]]
但是從上面的代碼中,“ list”數(shù)組輸出看起來像這樣:
[PropertyStart,a,b,c,PropertyEnd,PropertyStart,d,e,f,PropertyEnd,PropertyStart,....PropertyEnd]
我想您可能已經(jīng)注意到了差異。我無法達(dá)到預(yù)期格式的結(jié)果。請(qǐng)建議我任何解決方案!提前致謝!!
總結(jié)
以上是生活随笔為你收集整理的在java中arraylist_在Java中将ArrayList添加到另一个ArrayList的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java http2_java的okht
- 下一篇: 渣打银行是哪个国家