Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Date: Tue, 09 Oct 2012 14:16:47 -0600 Organization: Terminate and Stay Resident Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="75975abe3fe3503ca7350803ab98e478"; logging-data="29899"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VGAk1stUW/5+b282j1uI7" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:Wg/LTCVFXKDa7UKRO+7eWgxomw4= sha1:FeZjtiuK+wT8ZcLFJ4/g0BQ9sJs= Xref: csiph.com comp.lang.java.programmer:19206 Jan Burse writes: > Dear All, > > I just wonder whether I have overlooked something. > But could it be that LinkedHashMap is lacking the > following API: > > Map descendingMap(); > > So I can only iterate from oldest to youngest, and > not the other direction? > > Although under the hood it uses a double linked list, > and a reverse iterator would be simple. > > Also the whole matter seems to be complicated, since > the other collections have descendingMap() in an > Interface NavigableMap, which extends SortedMap. > > But SortedMap map assumes a compartor, whereby the > sorting in LinkedHashMap is implicit. > > Is there some shortcut to arrive at a reverse iterator > of LinkedHashMap? > > (Troll disclaimer: No I have no SSCCE (Short, Self > Contained, Correct (Compilable), Example). This is > a conceptual question.) > > Bye You haven't overlooked anything. The ability is not there and I don't see any simple way to add it without package access to java.util. LinkedHashMap is a bit of an oddity in the collections framework, but it's useful enough that I don't mind. If I really needed that functionality I'd probably try maintaining my own access-order list in parallel to the map. -- Jim Janney