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 files 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.
There is no such thing as a best data structure. What do you intend to do with these files? I presume you are already familiar with the different kinds of Set, List, Queue and Map?
Joined: Dec 31, 2010
i don't REALLY know them and what are their advantages. until i sort the file, i want them all in one data structure so i can iterate through them and filter them.
i was wondering if there is something faster then a TreeSet to do so, as TreeSet sorts by definition.
Joined: Oct 13, 2005
So you want them sorted? What about duplicates? Do they implement the Comparable interface, or can you implement a Comparator for your objects? You will need one or the other for a TreeSet.
What is the complexity of sorting a TreeSet? It should say in the documentation. Can you insert many instances in linear time, or logarithmic time? How does that compare with a List, and sorting it? Are your objects already in sorted order, or nearing sorted order? If your data are already sorted, a list might be better.
If you have answers to those questions, then TreeSet might be a good choice. It is easy enough to use, and simple in concept; you can write your own tree set in half an hour.