Another approach is along the lines you tried:

* Have the filenames and names in a map (key/value). * Take the key set and from it construct a sorted set * Go through the sorted set with a for...