I assume that the keys are strings. In this case, the order is in “character code” order (using the ASCII code for each character). So they are sorted, just not in the numeric order you’re expecting.
To put these in numeric order, the hashtable will need to be populated with Integer objects. Or, you can use an anonymous inner-class to compare the strings as numbers. Here’s a sample:
[highlight=java]
java.util.Hashtable h = new java.util.Hashtable();
h.put(“1”, “abcsdsdq”);
h.put(“-5”, “fed”);
h.put(“-1”, “gre”);
h.put(“45”, “abcsfdsw”);
h.put(“5”, “abcsfdswggdd”);
h.put(“4”, “abc”);
java.util.TreeMap tm = new java.util.TreeMap(
new java.util.Comparator() {
public int compare(Object o1, Object o2)
{
return ((new Integer((String)o1)).compareTo(new Integer((String)o2)));
}
public boolean equals(Object o1, Object o2)
{
return ((new Integer((String)o1)).equals(new Integer((String)o2)));
}
}
);
tm.putAll(h);
IDataCursor idc = pipeline.getCursor();
IDataUtil.put(idc, “ht”, h);
// You can put tm in the pipeline but it will fail when run in
// Developer because the Comparator isn’t Serializable, which
// is required for the pipeline transmission from IS to Developer
//IDataUtil.put(idc, “tm”, tm);
// Show the order of the keys in string lists
IDataUtil.put(idc, “htkeys”, h.keySet().toArray(new String[h.size()]));
IDataUtil.put(idc, “tmkeys”, tm.keySet().toArray(new String[h.size()]));
idc.destroy();[/highlight]
Hope this helps.
#webMethods#Flow-and-Java-services#Integration-Server-and-ESB