public class ActiveAlarm implements Comparable<ActiveAlarm> { public long timeStarted; public long timeEnded; private String name = ""; private String description = ""; private String event; private boolean live = false; public int compareTo(ActiveAlarm a) { if ( this.timeStarted > a.timeStarted ) return 1; else if ( this.timeStarted < a.timeStarted ) return -1; else { if ( this.timeEnded > a.timeEnded ) return 1; else return -1; } }
That should give you a rough idea. Once that's done, you can call Collections.sort()
on the list.