Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Date: Thu, 04 Oct 2012 23:01:48 +0200 Lines: 38 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net bm4LuAaozgXCfBVQpeKTwwU69DzPx4qG4SAPGbagp06y4hocY= Cancel-Lock: sha1:dSmszKKjF/3rCpJFwa/+LAKISZA= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:19108 On 04.10.2012 14:09, Jan Burse wrote: > 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? I guess they omitted it because the purpose is to provide a Map which always returns elements in insertion order (and not reverse insertion order). > 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. There you see why it's not in LinkedHashMap: it's neither a NavigableMap nor a SortedMap. > But SortedMap map assumes a compartor, whereby the > sorting in LinkedHashMap is implicit. There is no sorting going on - you just get insertion order. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/