Sort the files in the collection.


collection.sort(compare function(a, b File) int) Collection


compare function(a, b File) int

A callback function to decide if a or b shall come first in the resulting collection.

compare shall return:

  • a negative number to sort a before b,
  • 0 to preserve the relative order of a and b,
  • a positive number to sort b before a.


Return a new sorted collection. The order of files is determined by a user defined compare function. The sort is stable, that is, the original order of equal elements is preserved.

See also .sortBy() which is simpler and faster.


Sort files in the collection by name.