You can define a natural ordering for your class IceCream
by implementing the Comparator interface.
public class IceCream implements Comparator{
// ...
final String name;
final Date datedate;
public Icecream(String name, Date date){
this.name = name;
this.date = date;
}
public int compare(IceCreamObject o1, IceCreamObject o2) {
return ((IceCream)o1).date.compareTo(((IceCream)o2).date);
}
}