Re: LinkedHashMap next method ?
On Mon, 18 May 2009, Roedy Green wrote:
On Mon, 18 May 2009 12:50:18 +0200, Albert <albert@voila.fr> wrote,
quoted or indirectly quoted someone who said :
Hi, since LinkedHashMap keep the insertion order, why sun didn't add the
next method: K next(K key) ?
I need it because of speed of direct hash lookups (the hash part) and
order-based lookups (the next method). Is there an easy way to get that?
You can traverse the entire set in order with keySet
It is a slightly more strenuous requirement to be able to traverse,
starting at any point, but the way LinkedHashMap was implemented would
make it easy.
You could probably easily add the next method by extending the class
and using some protected fields and methods.
All the interesting bits are private, sadly.
I agree, the lack of the next method looks like an oversight. Perhaps
they fretted over how to de define it in a multithread environment.
I doubt it - the collections classes (the modern non-concurrent ones, that
is) pretty explicitly ignore threading issues.
tom
--
I am become Life, destroyer of worlds