[jdom-interest] Problems by sorting the list (JDOM beginner)

PJ Fanning pj.fanning at XIAM.com
Thu Mar 28 01:38:31 PST 2002


I would suggest the following.

List ch = root.getChildren;
Iterator it = ch.iterator ();
while (it.hasNext ()) {
	Object obj = it.next();
	it.remove();
}
Collections.sort (ch , mycomp);

The it.remove() will automatically update the root's list of children and
detach the children.

---Original Message---
One thing I found useful, while sorting list of childrens, is to detach them
prior to any 'processing' on them.

So I would say :

List ch = root.getChildren;
Iterator it = ch.iterator ();
while (it.hasNext ()) {
	Element element = (Element) it.next ();
	element.detach ();
}
Collections.sort (ch , mycomp);

Hope this helps.

Julien



More information about the jdom-interest mailing list