Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting a hash table

Status
Not open for further replies.

cramd2

Programmer
Jun 10, 2005
51
US
I have created a hash table and it works well, but I am having trouble understanding how a hash table sorts the data. The data that is in the hash table is bound to a drop down list, although, I don't find that I have any control of the sorting of the items listed. The hash table seems to work well for this situation that it allows me to enter "text" with corresponding "values".
cramd2
 
the hashtable will use compareto to sort the objects so your object should implement icomparable and override compareto the way you like it.



Christiaan Baes
Belgium

"My new site" - Me
 
chrissie1
I'm new to the hashtable and your suggestion "implement icomparable and override compareto the way you like it" could work, but I'm in the dark on this one. I'll be researching your suggestion, if you have any sites with examples to get me started, it would be helpful!
Thanks for your response!
cramd2
 
Here is a good article on collections


and this

Code:
public class MyObject : ParentObject, IComparable {
...

public int CompareTo(Object obj ) {
    MyObject myObject = (MyObject) obj;
    //priority is a double, which complicates matters, otherwise
    //  return this.priority-myObject.priority works well
    if(this.priority > myObject.priority) {
       return 1;
    } else if(this.priority < myObject.priority) {
       return -1;
    } else {
       return 0;
    }
 }
}

can be found here


Christiaan Baes
Belgium

"My new site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top