Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparator & Comparable

 
Arun Prasath
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could anyone tell me what is the difference between Comparator & Comparable interfaces? when do we use it?
 
Joe Ess
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A similar question came up last year: here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic