-1

I'm making a list of transactions, each transaction have a set of data fields including a calendar object. I would like to insert these transaction objects to a LinkedList based on the date in the transactions calendar object. In other words, sorted by date.

How can this be done?

Michael
  • 56
  • 2
  • 3
    Please clarify. What does "based on the date"? Do you mean that you want the list sorted by date? – JB Nizet Apr 10 '13 at 12:35
  • Yes, I wan't the sorted by date. – Michael Apr 10 '13 at 12:40
  • 1
    possible duplicate of [Sorting an ArrayList of Contacts based on name?](http://stackoverflow.com/questions/1814095/sorting-an-arraylist-of-contacts-based-on-name) and of many other questions explaining how to sort a list – JB Nizet Apr 10 '13 at 12:42
  • put them into a LinkedList and sort using comparator taking two transaction object and comparing their calendar fields. – khachik Apr 10 '13 at 12:45

1 Answers1

0

I'll just give it to you:

Collections.sort(list, new Comparator<MyClass>() {
    public int compareTo(MyClass a, MyClass b) {
        return a.getDate().compareTo(b.getDate());
    }
}
maba
  • 47,113
  • 10
  • 108
  • 118
Bohemian
  • 412,405
  • 93
  • 575
  • 722