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

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -