我有以下java代码,其中我试图将ArrayList复制到另一个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);
}
我希望“list”数组采用以下格式:
[[PropertyStart,a,b,c,PropertyEnd],[PropertyStart,d,e,f,PropertyEnd],[PropertyStart,......]]
但是从上面的代码中,“list”数组输出如下所示:
[PropertyStart,a,b,c,PropertyEnd,PropertyStart,d,e,f,PropertyEnd,PropertyStart,....PropertyEnd]
我想你可能已经注意到了差异。我无法达到预期格式的结果。
请建议我任何解决方案!
提前致谢!!