Quantcast
Channel: Deciding to use Comparable or Comparator - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by VGR for Deciding to use Comparable or Comparator

If your order was based only on numbers, Comparable would be fine.However, since your order (sometimes) involves lexical order of text,a Comparator class is better, since use of Comparable would mean...

View Article



Answer by onon15 for Deciding to use Comparable or Comparator

If there is a "natural" ordering, use Comparable. Rule of thumb for figuring out if the ordering is "natural" is, whether the order of the objects will always be that.Having said that, the decision...

View Article

Answer by Denys Séguret for Deciding to use Comparable or Comparator

The order you define here on your Product is very specific and will probably change in future versions of your programmight be enriched with contextual parameterizationwon't cover new featuresSo it can...

View Article

Deciding to use Comparable or Comparator

My program implements a Product class whose objects contain the following instance variables: name, priority, price, and amount.I have a LinkedList of Product objects that I need to sort before doing...

View Article
Browsing all 4 articles
Browse latest View live




Latest Images