|
-
May 10th, 2004, 06:26 PM
#1
Thread Starter
Hyperactive Member
best data structure
Hi everybody. I'm trying to choose the best data structure to hold the following information:
I have a Student class, which consists of several data member and methods. I need to be able to process a list of thousands of Students in any order, but I also need to be able to reference each Student from the list individually. I will adding to and removing form the list very frequently.
Would an ArrayList make the most sense for this?
Thanks.
Last edited by spandex44; May 11th, 2004 at 06:19 PM.
-
May 14th, 2004, 11:30 AM
#2
What do you mean by "in any order"? And what is the search key of the students? Some unique ID? Simply the array index (bad idea!)?
I recommend a binary tree, but depending on the finer points of your usage a hash table might be more appropriate. Besides, there's also the other issue of map or set: if you sort the objects by themselves you need a set (TreeSet, HashSet) and implement Comparable for Student (for TreeSet) or give Student.hashCode a meaningful override (for HashSet). If you sort by an external key you use a map (TreeMap, HashMap). Only the key type (probably a String or a Long) needs Comparable or hashCode, and both have it.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|