Portál AbcLinuxu, 5. května 2025 09:14
Jak jednoduše upravit tento kousek kódu, aby kromě seřazení podle data modifikace (což funguje), byly seřazeny položky se stejným datumem podle abecedy?
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File entry1, File entry2) {
long a, b;
a = entry1.lastModified();
b = entry2.lastModified();
if (a > b) {
return -1;
}
if (a == b) {
return 0;
}
if (a < b) {
return 1;
}
return 0;
}
});
public int compare(File entry1, File entry2) { int result=Long.compare(entry1.lastModified(),entry2.lastModified()); if (result==0) result=entry1.getName().compareTo(entry2.getName()); return result; });
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.