Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android sort array

how can i sort this array by date or name?

String[][] datetable= new String[21][2];

datetable[0][0] = "2011.01.01";
datetable[0][1] = "Name1";
datetable[1][0] = "2011.01.03";
datetable[1][1] = "Name2";
.
.
.
datetable[20][0] = "2011.02.16";
datetable[20][1] = "Name3";
like image 664
erdomester Avatar asked Feb 12 '11 21:02

erdomester


2 Answers

I would do what the poster linked to, only I wouldn't use final so much.

Arrays.sort(datetable, new Comparator<String[]>() {
    @Override
    public int compare(String[] entry1, String[] entry2) {
        // Sort by date
        return entry1[0].compareTo(entry2[0]);
    }
});
like image 156
Edawg Avatar answered Sep 24 '22 03:09

Edawg


This may help: Sort a two dimensional array based on one column

like image 36
evergreen Avatar answered Sep 25 '22 03:09

evergreen