![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e53. Implementing a Class That Can Be SortedIn order for a class to be used in a sorted collection such as aSortedTree or for it to be sortable by Collections.sort() ,
the class must implement Comparable .
public class MyClass implements Comparable { public int compareTo(Object o) { // If this < o, return a negative value // If this = o, return 0 // If this > o, return a positive value } }
e49. Terminating the Application e50. Determining When the Application Is About to Exit e51. Computing Elapsed Time e52. Loading Native Code e54. Redirecting Standard Output, and Error e55. Getting the Size of the Heap
© 2002 Addison-Wesley. |