• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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: 23605
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: 60860
190
  • 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: 60860
190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!