Use
Arrays.sort()
(see
Arrays (Java Platform SE 7 )[
^]) with a
Comparator (Java Platform SE 7 )[
^].
You can perform the sort on your orginal
listOfFiles
array or use a copy if that must be preserved.
Untested example which does not differentiate between files and folders:
Arrays.sort(listOfFiles, new Comparator<File>(){
public int compare(File f1, File f2)
{
boolean s1 = f1.getName().startsWith("s") || f1.getName().startsWith("S");
boolean s2 = f2.getName().startsWith("s") || f2.getName().startsWith("S");
if (s1 && !s2)
return -1;
if (s2 && !s1)
return -1;
return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
} });