sorting - To sort the collection of collection array list object in java -
class parentclass { private list<childclass>; } class childclasss { private date date; } list<parentclass> parentclasslist; how can sort parentclasslist objects date attribute of child class ? can use comparator ?
my requirements sort : need parentclassobject element on top has earliset date in child class objects.
for example: json notation of object
{ 'parentelement1':{ 'childelement1':{ 'date' : '2013-04-05' } }, 'childelement2':{ 'date' : '2013-03-01' } } }, 'parentelement2':{ 'childelement1':{ 'date' : '2013-04-01' } }, 'childelement2':{ 'date' : '2013-03-04' } } }
i think best way have parentclass implement comparable, , implement compareto can handle subclasses in desired way (for instance, if it's childclass, pay attention date attribute).
Comments
Post a Comment