nanode
01-24-2001, 02:15 PM
I'm having trouble determining the best way to treat a collection of objects for my situation.
I will create instances of objects that get manipulated (property changes, etc.) during runtime. To keep track of all these objects, I'd like to use an array-like container so I can conveniently iterate through the entire collection and other nice stuff.
Problem is, I need to be able to manipulate values of the object from the container and the instance directly.
MyClass m = new MyClass();
arrayListX.add(m);
//need to do either way below
m.setName("bob");
((MyClass)arrayList.get(0)).setName("bob");
I'm partial to a Hashtable, since each object has a unique index #, which I could use as a key - and would save exhaustive searches on an array or vector.
Will the last 2 lines of my code block accomplish the same thing? My real code is much more complex, so not as easy to experiment.
Thanks.
I will create instances of objects that get manipulated (property changes, etc.) during runtime. To keep track of all these objects, I'd like to use an array-like container so I can conveniently iterate through the entire collection and other nice stuff.
Problem is, I need to be able to manipulate values of the object from the container and the instance directly.
MyClass m = new MyClass();
arrayListX.add(m);
//need to do either way below
m.setName("bob");
((MyClass)arrayList.get(0)).setName("bob");
I'm partial to a Hashtable, since each object has a unique index #, which I could use as a key - and would save exhaustive searches on an array or vector.
Will the last 2 lines of my code block accomplish the same thing? My real code is much more complex, so not as easy to experiment.
Thanks.