B
Bruce
Hi
I am having a problem understanding the exact advantages of using an
ArrayList over a Hashtable in any situation.
In most areas of an application I am working on, lookup needs to be
fast. If I use a hashtable
Addition - O(1) - same as ArrayList
Removal - O(1) - same as ArrayList
Lookup- O(1) - ArrayList is O(n)
Memory - Maybe slightly more than ArrayList since we have a hash to
store.
And even if I need lookup by index which is easy using ArrayList, I
could simply use a Hashtable with the array index as the key and value
as my object.
The only other thing I do not know about is serialization efficiency.
So, my question is, anywhere I need lookup, I can just blindly use a
hashtable? In which situation would it be better to use an ArrayList?
Thanks
Bruce
I am having a problem understanding the exact advantages of using an
ArrayList over a Hashtable in any situation.
In most areas of an application I am working on, lookup needs to be
fast. If I use a hashtable
Addition - O(1) - same as ArrayList
Removal - O(1) - same as ArrayList
Lookup- O(1) - ArrayList is O(n)
Memory - Maybe slightly more than ArrayList since we have a hash to
store.
And even if I need lookup by index which is easy using ArrayList, I
could simply use a Hashtable with the array index as the key and value
as my object.
The only other thing I do not know about is serialization efficiency.
So, my question is, anywhere I need lookup, I can just blindly use a
hashtable? In which situation would it be better to use an ArrayList?
Thanks
Bruce