-1

I added 2 types of object to an object list. Now I want to compare date between them to sort them by date. Please show me how can I do that?

For example, the list is like this:

List<Object> mObjects = {ObjectType1,ObjectType2,ObjectType2,ObjectType1,ObjectType1....}
bon bon
  • 141
  • 1
  • 8
  • You have to override the equals method in your class. http://stackoverflow.com/questions/27581/what-issues-should-be-considered-when-overriding-equals-and-hashcode-in-java – underdog Aug 06 '15 at 04:59
  • what you have tried so far ? did you aware about Comparator and Comparable in Java ? – King of Masses Aug 06 '15 at 05:02

1 Answers1

0

You can use comparator for this. Since you have different types of objects, you can use a common interface with a getter for date field.

Amila
  • 4,977
  • 1
  • 24
  • 45