使用I am using sketchware IDE。如何按修改日期或时间对列表进行排序。
我使用了下面的代码
Arrays.sort(list, new Comparator<File>(){
@Override public int compare(File file1, File file2)
{
long k = file1.lastModified() - file2.lastModified();
if(k > 0)
{ return 1; }
else
if(k == 0)
{ return 0; }
else
{ return -1;
}
}
}
);但我得到一个错误:
The method sort(T[], Comparator<? super T>) in the type Arrays is not applicable for the arguments (ArrayList<String>, new Comparator<File>(){})发布于 2021-03-21 14:48:14
Arrays.sort()似乎不接受列表。
因此,如果要使用Arrays.sort(),则应首先将列表转换为数组,如下所示:
File[] filesArray = new File[files.size()];
filesArray = files.toArray(filesArray);然后使用filesArray变量调用该函数。
https://stackoverflow.com/questions/66729394
复制相似问题