java Android 排序数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4980720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:55:47 来源:igfitidea点击:
Android sort array
提问by erdomester
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";
回答by Edawg
I would do what the poster linked to, only I wouldn't use final
so much.
我会做海报链接的内容,只是我不会使用final
这么多。
Arrays.sort(datetable, new Comparator<String[]>() {
@Override
public int compare(String[] entry1, String[] entry2) {
// Sort by date
return entry1[0].compareTo(entry2[0]);
}
});
回答by evergreen
This may help: Sort a two dimensional array based on one column
这可能有帮助:基于一列对二维数组进行排序