开发者

Choosing the best data-sctructure for file storing

so my program gets a directory, filter the files according to different filters, then perform several actions and return the files in a desired order. i thought it is not necessary to order before i filter because then i would sort a lot of files for nothing. after the fil开发者_StackOverflow社区es are sorted i return them in a TreeSet.

so, my question is, what would be the best data structure to store the files before i put them in order? by best i mean in terms of run time of course. thanks, yotam


I agree with iluxa, just use an ArrayList. When you sort then you can use Collections.sort, as iluxa mentioned, but if you have a list of File objects (as opposed to just file name Strings) then you will need pass through a second parameter to the sort method. This will be an anonymous subclass of Comparator, something like the below:

Collections.sort(listOfDateObjects, new Comparator<File>() {

     @Override
     public int compare(File o1, File o2) {
         // put your comparison logic here
     }
});


A simple array should be fine. As you loop through the array of files, anything that passes your filters add to your TreeSet that you will return.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜