This week's book giveaway is in the
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Arduino in Action
this week in the
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
Programmer Certification (SCJP/OCPJP)
I m still not understanding COMPARABLE Interface
Joined: Nov 20, 2008
Mar 03, 2009 01:00:02
please give me SIMPLE ,COMPLETE example of Comparable interface.Also its main features.
Jesper de Jong
Joined: Aug 16, 2005
Mar 03, 2009 01:11:03
The reason why you're not getting good answers is because your question is very vague and general. Can you explain in more detail what exactly you don't understand about the Comparable interface?
Did you read the API documentation? What part of it did you not understand? Have a look at
The Collections Framework
, which explains how collections work, including the Comparable interface.
Try writing some code yourself to find out how it works. If your code doesn't work, post it here and ask questions about it.
Java Beginners FAQ
JavaRanch SCJP FAQ
The Java Tutorial
Java SE 7 API documentation
- My blog about Scala
Joined: Feb 24, 2006
Mar 03, 2009 01:47:23
Does this help
SCJP 6 articles
SCJP 5/6 mock exams
SCJP 5 Mock exam (Word document )
SCJP 5 Mock exam in Java.Inquisition format
Joined: Sep 13, 2007
Mar 03, 2009 11:15:35
a more common problem would be whether to use the
interface or the
interface. The goal of both of these interface is what?? sort object right?
Comparable uses the "compareTo(Object o)" method
Comparator uses the "compare(Object o1, Object o2)" method
If you implement either of these interfaces you normally override the equals and hashCode methods and good idea to override toString too.
Both of the above methods uses the equals method to compare in order to sort that object.
Talking about sort, using Collection.sort() only sort strings and primitive collections. More complicated objects would not be appropriate so using either of these is the way to go.
At the end of the day, use Comparable to do simple sorting, otherwise use Comparator to have more control.
Best to is to
out both by sorting the same object.
I agree. Here's the link:
subject: I m still not understanding COMPARABLE Interface
collections: why duplicates arent getting eradicated?
can anybody tell about comparator in java
sorting by a primitive int field
Couple of Problems
sorting of a list having bean object
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013