• 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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
Posts: 23813
140
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: 62819
203
  • 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: 62819
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
java tutor first lesson for free
https://coderanch.com/t/702613/java-tutor-lesson-free
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!