This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Comparator & Comparable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparator & Comparable" Watch "Comparator & Comparable" New topic
Author

Comparator & Comparable

Arun Prasath
Ranch Hand

Joined: May 23, 2007
Posts: 80
Hi,

Could anyone tell me what is the difference between Comparator & Comparable interfaces? when do we use it?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

java.lang.Comparable

This interface imposes a total ordering on the objects of each class that implements it.


java.util.Comparator
A comparison function, which imposes a total ordering on some collection of objects. Comparators can be passed to a sort method (such as Collections.sort or Arrays.sort) to allow precise control over the sort order.

[ May 14, 2008: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
A similar question came up last year: here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparator & Comparable
 
Similar Threads
Interface
Difference in between comparable and comparator interface
sorting of a list having bean object
difference between Comparator and Comparable interface
Sort a list