Skip to main content
added 20 characters in body
Source Link
GETah
  • 21.4k
  • 7
  • 66
  • 108

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);
    }
}

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 date
    public Icecream(String name, Date date){
       this.name = name;
       this.date = date;
    }
    public int compare(IceCream o1, IceCream o2) {
        return o1.date.compareTo(o2.date);
    }
}

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 date;
    public Icecream(String name, Date date){
       this.name = name;
       this.date = date;
    }
    public int compare(Object o1, Object o2) {
        return ((IceCream)o1).date.compareTo(((IceCream)o2).date);
    }
}
Source Link
GETah
  • 21.4k
  • 7
  • 66
  • 108

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 date
    public Icecream(String name, Date date){
       this.name = name;
       this.date = date;
    }
    public int compare(IceCream o1, IceCream o2) {
        return o1.date.compareTo(o2.date);
    }
}