• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Diferents between Comparable and Comparator Interfaces

 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Can someome explain me the very diferencias between Comparable and Comparator Interfaces.

I know that the Comparable Interface needs to implements the method:
->int compareTo(T o)

And Iknow too that the Comparator Interface needs to implements the method:
->int compare(T o1, T o2)

But I want to know more the very diferencias.

Very thanks
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Comparable" is an adjective. If an object is Comparable, it has the ability to compare itself to some other object.

"Comparator" is a noun. A Comparator is an object with the ability to compare 2 other objects to each other.
[ January 23, 2008: Message edited by: marc weber ]
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marc i got it! thankz
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Comparator interface has to be implemented by the class ,Object of which you want to compare with Other Objects.

But Comparator interface can be implemented by any class and give you power to
compare any two Objects.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!