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";
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]);
}
});
This may help: Sort a two dimensional array based on one column
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With