java - How to sort a 2-d array based upon column of dates in ascending order -


import java.util.comparator; import java.util.date;  //class  returns string columnn in ascending order  public class datecompare implements comparator {      int columntosort;     datecompare(int columntosort) {         this.columntosort = columntosort;     }      //overriding compare method     public int compare(object o1, object o2) {         date[] row1 = (date[]) o1;         date[] row2 = (date[]) o2;         //compare columns sort         return row1[columntosort].compareto(row2[columntosort]);     } } 

my 2-d array stores phone names , dates of manufacture. friends,i have made class named datecompare sorts 2-d array of records based upon column stores dates. not giving desired output.can rectify or give better substitute solution because couldn't find clear answer on site? in advance!!!

input(for example):

samsung                   01/01/2014 iphone                    09/02/2006 motorola                  16/06/2009 

output:

iphone                    09/02/2006 motorola                  16/06/2009 samsung                   01/01/2014 

why 2d array, why not write class hold data in structured manner?

public class mytuple implements comparable<date>  {     string phone;     date date;      @override      public int compareto( date d )     {          return d.compareto( this.date );     } } 

and use list<mytuple> instead of array? believe joachim sauer on site taught me phrase "object denial" of example :-)

cheers,


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -