[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:



public static void sortContent(Element element, Comparator comparator) {
    // Get a List of the current children
    List contentList = element.getContent();

    // Temporarily remove all content

    // 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

More information about the jdom-interest mailing list