• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused about building a reverse Comparator  RSS feed

 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know Ive done this at one point in time but I cant seem to find my code anywhere & now Ive only managed to confuse myself completely!
What Im looking to do is get results from a db where the primary key is an int, put them into a TreeMap in REVERSE order (largest first, etc) using the int as the key (as an Integer) & the rest of the results in an object for the value. Ive stared at the API & a few examples on the web but just dont get it ( building the Compartor that is).... really think Im having one of those DUH days to be honest) An example would be wonderful .... I know Im gonna feel like an idiot when I see it but definately feel like I need a kick in the head .... thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compare() method has to return a negative, zero, or positive value depending on whether the first object comes before, goes next to, or comes after the second object. If I explain it this way, do you now understand what to do? By reversing the sign of the return value, you reverse the sort order; simple, yes?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!