I am trying to implement something reading in a large number of parameters (the exact number is not pre-known, below 300, say). The parameter itself is actually the lowest layer of this hierarchy.
Then I have the second layer called Cell, each containing this many Paras. Now comes the third layer 'ControlCenter', each containing between 200 and 300 Cells, as well as below 100 Paras of itself. And I need to have around 100 ControlCenter (to be organized in a certain way too) in the program.
I wonder what is(are) the appropriate way(s) to collect these Para, Cell, ControlCenter. The thing in common is I don't know the exact number of instances for each of them, but it will be several hundred as I have noted already; also it wouldn't be required to take any instance away from the collection once it's added.
Two of the choices I have been thinking of so far are Array and ArrayList. The argument for Array is clear, the thing against it is I shall always be checking about the non-null end; on the other hand, ArrayList is more flexibel, but also expensive in the sense of accessing speed and so on.
My question, what would you suggest me to use, array, arraylist, or something else? And your reason please.
If your application is multi-threaded, Vector might be needed.
Basically, I would suggest you use ArrayList. If once your program is completed, it needs to be optimised, all interfaces should be able to remain the same and you can re-code it with arrays. However, I doubt if that'd be necessary.
The Properties class could handle your parameters that you read in. You could create Cell and ControlCenter classes which have Properties member variable to hold them.
Properties are just key, value pairs that can be read or written to or from a test file.
I do not think we know egnough of your application to decide, it really depends of what you want to do with your application: searching through your lists, lots of additions/deletions, multithreading, ...
My usual advice in this case is go for the List interface (with your implementation of choice). When you will know the usage pattern of the application, then make your choice ... it might be that the good solution for you are arrays, but LinkedList might more suitable, or even sets. It really depends on what people will do with this structure, and not on this implementation vs. that other one.
All these operation anyway you have to do even if you are handling your params with array. for example you have to maintain a counter, you have to add to the array and stuff like that. So I don't think for basic operations like add and get ArrayList is going to be expensive than an array.
However when you use an ArrayList it can perform all the other sort of functions like converting to array adding a collection which as you have mentioned will be expensive. But you can choose not to use them if you don't want to but using an ArryaList you will always have these functionality with you whenever you need them.
Moreover another reason to go for ArrayList is because in J2SE 1.5 in the future there will be Generics introduced and also there will a new kind of for loop introduced to iterate over collections. Which will make your life even easier.
Another problem with ArrayList now which is not there in array is when you take out the Objects in ArrayList you have to cast them which might reduce some performance but then again in 1.5 the Generics should solve this problem.
So if you ask me between ArrayList and array my vote is for ArrayList.