[jdom-interest] Sorting a list of text elements

Bruce Altner baltner at hq.nasa.gov
Fri Mar 16 04:42:20 PST 2001


I am trying to sort a list of text elements within my servlet, which uses 
JDOM, for a pull down menu and am not getting it to work. Maybe I'm using 
the sort method (part of the Java 2 Collections framework) 
incorrectly.  Here is the code snippet:

     //get root and all first level children (as List)
     Element root = doc.getRootElement();
     Element menuItems = root.getChild("Categories");
     List menuItem = menuItems.getChildren();

     out.println("       <td><SELECT NAME=\"category\">");
     for(int i=0;i<menuItem.size();i++){
     Element elem = (Element)menuItem.get(i);
     String menuItemText = elem.getTextTrim();
     out.println("       </SELECT>");

The Collections.sort(menuItem) line has no effect: the list is not sorted. 
I am expecting alphabetical sorting as the "natural order." Can someone 
point out what I need to do?

Thanks, in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20010316/a5900d95/attachment.htm

More information about the jdom-interest mailing list