This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Collections framework: is sort() always stable?
Posted by Steven Tolkin on April 24, 2000 at 5:45 PM
Is there a guarantee that sort() will be stable? Suppose I implement a faster sort algorithm that is not stable. For example one can sort integers in log log n (sic) time. Am I "allowed" to use a non-stable sort for sort()? If so code that depended on sort being stable will likely break. Perhaps we should encourage naming this nonstableSort() as a precaution. (This kind of guarantee is very hard to express, even if "programming by contract" is later added to Java. Does Eiffel have a solution to this? Or must we rely on conventions, e.g. names for methods, etc.)
Replies:
|