Close
jGuru Forums
Posted By: raffe_paffe Posted On: Tuesday, July 17, 2001 07:54 AM
Do you know of a collection (or other class) that has he same functionallity as hashtable (key - value pair) but is sorted like an array(in order you put it in stuff, so to say)?
Re: order hashtable as array
Posted By: Luke_Biewald Posted On: Friday, July 20, 2001 06:08 PM
Posted By: raffe_paffe Posted On: Wednesday, July 18, 2001 12:40 AM
java.util.SortedMap myMap = new java.util.TreeMap(new java.util.Comparator() { public int compare(Object o1, Object o2) { return 1; } public boolean equals(Object o1, Object o2) { return o1.equals(o2); } } ); Any thoughts?
Posted By: John_Zukowski Posted On: Tuesday, July 17, 2001 10:27 AM
If all you want to do is sort them based on some key, use a TreeMap.
Posted By: Naveed_Azhar Posted On: Tuesday, July 17, 2001 08:20 AM
public Hashtable htobject = new Hashtable();........................ SortedSet sortedKeys = new TreeSet(htobject.keySet()); Iterator it = sortedKeys.iterator(); while ( it.hasNext() ) { NaveedClass temp = (NaveedClass)htobject.get((String)it.next()); System.out.println(temp.toString()); }