<html>
Greetings:<br>
<br>
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:<br>
<br>
//get root and all first level children (as
List)<br>
Element root = doc.getRootElement();<br>
Element menuItems =
root.getChild("Categories");<br>
List menuItem = menuItems.getChildren();<br>
<b>Collections.sort(menuItem);<br>
<br>
</b>
out.println("<x-tab> </x-tab><td><SELECT
NAME=\"category\">");
<dl>
<dd> for(int i=0;i<menuItem.size();i++){
<dl>
<dd> Element elem = (Element)menuItem.get(i);
<dd> String menuItemText = elem.getTextTrim();
<dd>
out.println("<OPTION>"+menuItemText+"</OPTION>");
</dl>
<dd> }
</dl>
out.println("<x-tab> </x-tab></SELECT>");<br>
<br>
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?<br>
<br>
Thanks, in advance,<br>
Bruce</html>