• 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

Sorted TreeSet from HashSet

 
Greenhorn
Posts: 29
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to sort HashSet<SomeObject> into a sorted TreeSet. I have an object like :


I need to implement 'comparable' also to get the result with respect to my other sorting algo. Here is my code snippet :

It's not giving me the sorted list. It just give only the first element which got inserted first. I'm not able to find out the prob, where i'm wrong.


 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code provided seems will not compile. You tend to create an objects set, but you intend to do operation on object variable. The SomeObject is made to implement Comparator but the method implemented is compareTo().



Anyways, below sample code does descending sorting on a TreeSet based on a custom comparator.
reply
    Bookmark Topic Watch Topic
  • New Topic