-----------------------------
Or maybe it will use more memory and time? The problem is that I am going to
iterate frequently, so I do not want the heap to grow fast before garbage
collector does its job.
I simply do not know what TreeMap.values() does actually...
It seems that a new object is created (this means some memory and time)...
luckily, the elements seem not to be copied ("The collection is backed by
this TreeMap instance, so changes to this map are reflected in the
collection, and vice-versa"). I could preserve the reference between
iterations and so save time and space if I iterate frequently. But if no
object is really created, and the method just returns a reference to the
member, then this is useless effort.
Well, then I have to get Collection.iterator()... this time I cannot
preserve its value between iterations because it is forward-only. Will this
call create a new object on each iteration or maybe it will return a
reference to some existing object?
Finally, if the collection and map base on the same elements, then I have no
idea of how fast Iterator.next() is going to be :-/.
Well maby something else than TreeMap?
My requirements:
a. fast access to elements by key,
b. keys are integers, but not a contiguous range [0..n];
they might start above zero and many keys might be missing
in the range,
c. frequent iterating of the elements must be fast and memory efficient,
d. iteration must return elements in order of keys or in order
they were added to the structure,
e. variable number of elements (but adding and removal needs
not to be extremely fast)
Thanks for any help in advance.
DW.