I have an array of filenames and need to sort that array by the extensions of the filename. Is there an easy way to do this?
You can implement a custom Comparator of Strings. Make it sort them by the substring after the last index of '.'
. Then pass in the comparator and your array into
Arrays.sort(stringArray, yourComparator);
// An implementation of the compare method
public int compare(String o1, String o2) {
return o1.substring(o1.lastIndexOf('.')).compareTo(o2.substring(o2.lastIndexOf('.'));
}