【发布时间】:2011-12-11 21:22:21
【问题描述】:
例如,我有两个对象:
Icecream ice1 = new Icecream(vanilla, newDate(11, 09, 09));
Icecream ice2 = new Icecream(choko, newDate(10, 08, 08));
// where first argument is a String and second argument is a Date
我怎样才能打印出来,以便从最早的日期开始订购? (toStrign 方法已经配置好了)
输出应该是:
Vanilla, 10-08-08
Vanilla, 11-09-09
谢谢!
【问题讨论】:
-
docs.oracle.com/javase/tutorial/collections/interfaces/… - Oracle 教程是谷歌搜索“java 对象排序”时的第三个链接
-
搜索论坛。关于如何实现 Comparable 接口或创建自定义 Comparator 的示例有数百个。
标签: java sorting constructor