Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35513
| From | j4n bur53 <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: ArrayList vs HashMap |
| Date | 2016-08-31 09:15 +0200 |
| Organization | albasani.net |
| Message-ID | <nq605l$14g$1@news.albasani.net> (permalink) |
| References | <ps7urbhve2c7lfn0f3nop1p0hkgjsgdaid@4ax.com> |
Roedy Green schrieb: > Hash anyone ever experimented to find a rule of thumb about what sizes > lookup should be done with ArrayList and which with HashMap? The Java compiler implements some rule of thumbs in its switch statement compilation. It has two options to emit a scan or an index lookup byte code instruction. Similarly you can use an array list to scan and implement a map. Just store key value pairs or distribute the keys and values along array elements, resulting in an array of double size. Here is the Java heuristic: http://stackoverflow.com/a/31032054/502187 This doesn't directly answer your question, but I have a similar case between ArrayList and HashSet, and simply used threshold on the number of key value pairs which I determined empirically. There is not only a time tradeoff but also a space tradeoff. Since using less space was also important for me I was choosing a higher threshold of 12 key value pairs or so. Otherwise I would use 8 key value pairs or so. Bye
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
ArrayList vs HashMap Roedy Green <inquiry@mindprod.com> - 2016-08-25 09:42 -0700
Re: ArrayList vs HashMap Roedy Green <inquiry@mindprod.com> - 2016-08-25 09:43 -0700
Re: ArrayList vs HashMap Eric Douglas <e.d.programmer@gmail.com> - 2016-08-25 10:06 -0700
Re: ArrayList vs HashMap Roedy Green <inquiry@mindprod.com> - 2016-08-30 16:34 -0700
Re: ArrayList vs HashMap Andreas Leitgeb <avl@logic.at> - 2016-08-31 12:55 +0000
Re: ArrayList vs HashMap Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-08-31 13:05 -0400
Re: ArrayList vs HashMap Andreas Leitgeb <avl@logic.at> - 2016-08-31 17:34 +0000
Re: ArrayList vs HashMap j4n bur53 <janburse@fastmail.fm> - 2016-08-31 09:15 +0200
csiph-web