I am having the following java code, in which I am trying to copy the ArrayList to another ArrayList.
ArrayList<String> nodes = new ArrayList<String>();
ArrayList NodeList = new ArrayList();
ArrayList list = new ArrayList();
for (int i = 0; i < PropertyNode.getLength() - 1; 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);
}
I want the "list" array to be in this format:
[[PropertyStart,a,b,c,PropertyEnd],[PropertyStart,d,e,f,PropertyEnd],[PropertyStart,......]]
But from the above code, the "list" array output is seen like this:
[PropertyStart,a,b,c,PropertyEnd,PropertyStart,d,e,f,PropertyEnd,PropertyStart,....PropertyEnd]
I think you might have noticed the difference. I am not able to achieve the result in expected format.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…