Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27937

Re: LinkedHashMap - get latest key?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Jeff Higgins <jeff@invalid.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: LinkedHashMap - get latest key?
Date Wed, 02 Apr 2014 12:06:24 -0400
Organization A noiseless patient Spider
Lines 23
Message-ID <lhhcmb$9p7$1@dont-email.me> (permalink)
References <slrnljo8ia.rhr.avl@login.logic.tuwien.ac.at>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Wed, 2 Apr 2014 16:08:43 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="6b9e92482af47766954d85fb77d372f5"; logging-data="10023"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Wj+oMGYg2c+lgyxWqQU6m5HtPH/eyiUA="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10
In-Reply-To <slrnljo8ia.rhr.avl@login.logic.tuwien.ac.at>
Cancel-Lock sha1:AiI8srvpdAmDjgrtcPI/BCVtupE=
Xref csiph.com comp.lang.java.programmer:27937

Show key headers only | View raw


On 04/02/2014 10:44 AM, Andreas Leitgeb wrote:
> Given a LinkedHashMap instance, what would be a
> reasonable way to obtain the latest added key?
>
> The specific definition of "reasonable" being:
>   - no separate keeping track of key-sequence
>   - it should be a O(1) operation, and not
>      have to iterate all keys.
>
> Unlike TreeMap, the LinkedHashMap doesn't implement
> NavigableMap.
>
> If nothing else helps, I'll need to switch to a LinkedList,
> and thereby sell the "O(1)" of searching for an Object (by
> key) in exchange for a "O(1)" of obtaining the last Object.
>
> It just seems odd to me, that a LinkedHashMap doesn't
> have such a nobrainer getter, or, that a LinkedHashMap
> isn't also a NavigableMap with the natural ordering
> induced by position.
>
?
Collections.max(myMap.entrySet())

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

LinkedHashMap - get latest key? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-02 14:44 +0000
  Re: LinkedHashMap - get latest key? Jeff Higgins <jeff@invalid.invalid> - 2014-04-02 12:06 -0400
    Re: LinkedHashMap - get latest key? Jeff Higgins <jeff@invalid.invalid> - 2014-04-02 12:44 -0400
      Re: LinkedHashMap - get latest key? Jeff Higgins <jeff@invalid.invalid> - 2014-04-02 13:13 -0400
        Re: LinkedHashMap - get latest key? Jeff Higgins <jeff@invalid.invalid> - 2014-04-02 13:19 -0400
          Re: LinkedHashMap - get latest key? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-02 21:58 +0000
  Re: LinkedHashMap - get latest key? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2014-04-16 21:33 -0700
  Re: LinkedHashMap - get latest key? leif.roar@invalid.com (Leif Roar Moldskred) - 2014-04-17 03:32 -0500
    Re: LinkedHashMap - get latest key? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-19 12:51 +0000
      Re: LinkedHashMap - get latest key? v_borchert@despammed.com (Volker Borchert) - 2014-04-21 20:38 +0000
        Re: LinkedHashMap - get latest key? Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-04-25 09:18 +0000

csiph-web