[jdom-interest] Sorting Children, Collections.sort, ComodificationException, etc., etc.
Bradley S. Huffman
hip at a.cs.okstate.edu
Mon Sep 23 10:07:54 PDT 2002
This subject sure does seem to come up alot, so I'll throw out my solution.
Alex has a similar solution at:
http://www.servlets.com/archive/servlet/ReadMsg?msgId=211785&listName=jdom-interest
Brad
public static void sortContent(Element element, Comparator comparator) {
// Get a List of the current children
List contentList = element.getContent();
// Temporarily remove all content
element.setContent(null);
// All Elements, Text, Comments, etc. in contentList are now detached
// from the parent element so it is safe to sort the list.
Collections.sort(contentList, comparator);
// Add the sorted content back
element.setContent(contentList);
}
More information about the jdom-interest
mailing list