• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

what is comparator in sorted set  RSS feed

 
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the document

http://docs.oracle.com/javase/7/docs/api/java/util/SortedSet.html#comparator()

But I am not able to get what is actual use of this in set ?


Thanks
 
author
Sheriff
Posts: 23569
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kishor Joshi wrote:
http://docs.oracle.com/javase/7/docs/api/java/util/SortedSet.html#comparator()

But I am not able to get what is actual use of this in set ?



A comparator is something whose purpose is to compare two elements. It is passed to the sorted set, for cases where you want the sorted set to sort elements which are not comparable. Or if you want the elements sorted in a fashion that is different from the natural ordering provided by the comparable elements.

Henry
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any example using code?

can you explain
 
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kishor Joshi wrote:any example using code?

can you explain



Hi Kishor. Comparators can be a bit tricky to understand. I found this link very helpful, give it a read http://javahash.com/java-comparator-and-comparable-demystified/
 
Marshal
Posts: 59765
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One part of the Java Tutorials you might do well to read is about Collections. Read it very quickly and you will forget 99% of what you read. No problem: you can always go back and read it again.

As you go through it, you will come across a section about object ordering. That tells you about Comparators.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks campbell

I will go for these links
 
Campbell Ritchie
Marshal
Posts: 59765
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!