My problem is actually more nuanced than the question suggests, but wanted to keep the header brief.
I have a HashMap<String, File> of File objects as values. The keys are String name fields which are part of the File instances. I need to iterate over the values in the HashMap and return them as a single String.
This is what I have currently:
private String getFiles() { Collection<File> fileCollection = files.values(); StringBuilder allFilesString = new StringBuilder(); for(File file : fileCollection) { allFilesString.append(file.toString()); } return allFilesString.toString(); }
This does the job, but ideally I want the separate File values to be appended to the StringBuilder in order of int fileID, which is a field of the File class.
Hope I’ve made that clear enough.
Something like this should work: