Easy way to Sort ArrayList of Files By Filename?

?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Is there an easy way to sort an ArrayList of objects or Files by
filename?

If the objects implement Comparer or you supply an instance of
something that implements Comparable, then you can use
Collections.sort !

Arne
 
P

Patricia Shanahan

Is there an easy way to sort an ArrayList of objects or Files by
filename?

File does implement Comparable. The comparison is based on the abstract
path name. If that is what you want, use the single argument form of
Collections.sort

If you want to sort e.g. by just the actual file name, not the whole
path name, or if you want to sort objects of a class that does not
implement Comparable, use the two argument form of Collections.sort and
provide your own Comparator.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top