Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unboxing is fast - no allocations are required. Boxing is a potentially slower, as it needs to allocate a new object (unless it uses a pooled one).</p> <p>Are you sure you've really got a problem though? Don't complicate your code until you've actually proved that this is a significant hit. I very much doubt that it is.</p> <p>There are collection libraries available for primitive types, but I would stick to the normal HashMap from the JRE until you've profiled and checked that this is causing a problem. If it really only is <em>thousands</em> of lookups, I very much doubt it'll be a problem at all. Likewise if you're lookup-based rather than addition-based (i.e. you fetch more often than you add) then the boxing cost won't be particularly significant, just unboxing, which is cheap.</p> <p>I would suggest using <code>intValue()</code> rather than the cast to convert the value to an <code>int</code> though - it makes it clearer (IMO) what's going on.</p> <p>EDIT: To answer the question in the comment, <code>HashMap.get(key)</code> will be faster than <code>ArrayList.indexOf(key)</code> <em>when the collection is large enough</em>. If you've actually only got five items, the list may well be faster. I assume that's not really the case though.</p> <p>If you really, really don't want the boxing/unboxing, try <a href="http://trove4j.sourceforge.net/" rel="nofollow noreferrer">Trove</a> (TObjectHashMap). There's also <a href="http://acs.lbl.gov/~hoschek/colt/" rel="nofollow noreferrer">COLT</a> to consider, but I couldn't find the right type in there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload