Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18464
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Robert Klemme <shortcutter@googlemail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Question about HashMap and Map.Entry ... |
| Date | Fri, 31 Aug 2012 07:27:50 +0200 |
| Lines | 35 |
| Message-ID | <aab0asF8ntU1@mid.individual.net> (permalink) |
| References | <slrnk3v9ba.u9l.avl@gamma.logic.tuwien.ac.at> <k1o8uk$7m5$1@dont-email.me> <35O%r.171$_I7.84@newsfe20.iad> <slrnk3vff3.u9l.avl@gamma.logic.tuwien.ac.at> <slrnk3vftg.u9l.avl@gamma.logic.tuwien.ac.at> <BKP%r.91$R_4.31@newsfe05.iad> <slrnk3vo9j.u9l.avl@gamma.logic.tuwien.ac.at> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net KNDcIpAa+SOOpjuv0N3E8w3gRnxSJQX5DlseH5JZgzKcWxHnLRJBmgBhbr80Qg8Jk= |
| Cancel-Lock | sha1:FNp2gzd1kOVAGFBZ4SZfdoEW218= |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 |
| In-Reply-To | <slrnk3vo9j.u9l.avl@gamma.logic.tuwien.ac.at> |
| Xref | csiph.com comp.lang.java.programmer:18464 |
Show key headers only | View raw
On 30.08.2012 23:55, Andreas Leitgeb wrote: > Daniel Pitts <newsgroup.nospam@virtualinfinity.net> wrote: >> On 8/30/12 12:32 PM, Andreas Leitgeb wrote: >>> Damn, on re-read, I notice, that my own implementation of >>> Map.Entry could just hold a ref to the map and implement >>> setValue() to write the value back into the Map... >> Or, if you know all the keys before hand, you can use instead Map<Long, >> MyLongWrapper> map. > > I know all the relevant keys before hand. I currently do > an initial map.put(k,0L) for each relevant "k". > >> MyLongWrapper would have .set() and .get(), or even .actUpon() >> depending on the semantics you need. > > Indeed, that is a more elegant approach, than mine. > Although it won't save me the extra containsKey(), as I'll > be also having "k"s that aren't in the map, containsKey() is unnecessary work. Just get(), and if it's null create a new MyLongWrapper. Btw, if you use long as member instead of Long then you do not even necessarily have more objects. containsKey() is only ever useful if you have null values in a Map or are just interested in the fact whether a key is present or not. Other than that just get() is more efficient even though effects might be negligible. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 17:39 +0000
Re: Question about HashMap and Map.Entry ... markspace <-@.> - 2012-08-30 10:46 -0700
Re: Question about HashMap and Map.Entry ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-30 11:15 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 19:24 +0000
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 19:32 +0000
Re: Question about HashMap and Map.Entry ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-30 13:08 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 21:55 +0000
Re: Question about HashMap and Map.Entry ... Robert Klemme <shortcutter@googlemail.com> - 2012-08-31 07:27 +0200
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-31 10:26 +0000
Re: Question about HashMap and Map.Entry ... Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-31 11:22 -0700
Re: Question about HashMap and Map.Entry ... Robert Klemme <shortcutter@googlemail.com> - 2012-09-01 11:06 +0200
Re: Question about HashMap and Map.Entry ... markspace <-@.> - 2012-08-30 14:30 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 22:42 +0000
Re: Question about HashMap and Map.Entry ... markspace <-@.> - 2012-08-30 14:34 -0700
Re: Question about HashMap and Map.Entry ... Lew <lewbloch@gmail.com> - 2012-08-30 13:42 -0700
Re: Question about HashMap and Map.Entry ... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2012-08-30 22:34 +0000
csiph-web