It can't. However, I don't blame Arne for responding as he did, given
that you explicitly called out "will clone itself when it gets full and
is rather slow". To me (and presumably to him) that clearly implies
that the operation you're concerned with at that particular moment is
adding, not searching. It seems reasonable to me to point out that the
addition operation for both data structures is constant order, and that
the cost of "cloning" is present in both.
But even a hash table is slower for searching than simply enumerating a
list that's already been sorted (as in the OP's question). So,
please...tell us why the hash table is the preferred solution here?
Pete
From reading the OP, i thought that they where inserting double values
into a data structure and wanted to make sure that the value that they
were adding was not already stored in the data structure. To me this
means they will need to compare every insert item with ever single item
in the list O(n). Doing this with a ArrayList is a lot slower than a hash
table, as you could hash the double value to find out which linked list
the value would be stored in, then just check the few values in the list.
When an array list is full is needs to be cloned to another larger array
list. I thought that hash tables where are array of linked lists (Also
known as a bucket array) this means they can never be full (will use SWAP/
Virtual Memory when RAM is full), but the more items that are in each
linked list the slower the search time becomes, the insert time of a
linked list is always O(1) if you are adding to the tail of the list.
If the OP is using a ArrayList and would like to keep the items in order
when inserting a new item this would mean moving all of items along one
in the list, again another slow process, maybe a tree of some kind would
be a better option.
I was always taught to stay away from ArrayList at all costs. Arrays are
fine if you know the amount of items that you would like to store, and
they have a fast data access compared to a list as you do not have to
iterate all of the items to find the one you require.
j1mb0jay