• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confused about building a reverse Comparator

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic