Iterator i = root.elementIterator();
Element e = ((Element)i.next());
for(i = root.elementIterator(); i.hasNext(); )
{
Element element = ((Element)i.next());
//System.out.print(element.attributeValue("name")+"\t\t");
//System.out.print(element.attributeValue("type")+"\n");
System.out.print(element.getText()+"\n");
sName.add(element.getText());
//i=((Iterator) i.next());
//下面想要遍历i.next()的下一个元素,该怎么改呢?
Element element1 = ((Element)i.next());
sType.add(element1.getText());
}
//把属性值写入ArrayList并打印
System.out.println("********************************");
我想要实现一下子遍历两个元素,应该怎么修改呢?
Iterator Java 遍历
------解决方案--------------------
就是你写的那样啊 或者你没说明白
------解决方案--------------------
Iterator i = root.elementIterator();
while(i.hasNext() )
{
Element element = ((Element)i.next());
System.out.print(element.getText()+"\n");
sName.add(element.getText());
//i=((Iterator) i.next());
//下面想要遍历i.next()的下一个元素,该怎么改呢?
Element element1 = ((Element)i.next());
sType.add(element1.getText());
}
//把属性值写入ArrayList并打印
System.out.println("********************************");