Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Question about HashMap and Map.Entry ... Date: Thu, 30 Aug 2012 10:46:57 -0700 Organization: A noiseless patient Spider Lines: 22 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 30 Aug 2012 17:47:00 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="7877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18itTYNrueTmD++55Qy+3Xb++oiKJavXQw=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 In-Reply-To: Cancel-Lock: sha1:fVLdYpnMFCM3B9n1XdLJ0n1cPJM= Xref: csiph.com comp.lang.java.programmer:18438 On 8/30/2012 10:39 AM, Andreas Leitgeb wrote: > What I'm missing, however, is: > How would I get the Entry for a given key? What about: Long value = hashMap.get( key ); if( value != null ) hashMap.put( key , newValue ); This only updates the value for key if key is already present. I think that's what you said you are doing. It assumes that "null" is not a valid value for any key. (That can be changed as well, but it's basically a scan through the entries at that point.)