Skip navigation links


Provides various Comparator implementations for Files.

See: Description

Package Description

Provides various Comparator implementations for Files.


All the comparators include convenience utility sort(File...) and sort(List) methods.

For example, to sort the files in a directory by name:

 File[] files = dir.listFiles();

...alternatively you can do this in one line:

 File[] files = NameFileComparator.NAME_COMPARATOR.sort(dir.listFiles());

Composite Comparator

The CompositeFileComparator can be used to compare (and sort lists or arrays of files) by combining a number of other comparators.

For example, to sort an array of files by type (i.e. directory or file) and then by name:

 CompositeFileComparator comparator =
 new CompositeFileComparator(
 File[] files = dir.listFiles();

Singleton Instances (thread-safe)

The Comparator implementations have some convenience singleton(thread-safe) instances ready to use:

Skip navigation links

Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.