title: SparseArray vs HashMap
body: <p>I can think of several reasons why <code>HashMap</code>s with integer keys are much better than <code>SparseArray</code>s:</p>
  
  <ol>
  <li>The Android documentation for a <code>SparseArray</code> says "It is generally slower than a traditional <code>HashMap</code>".</li>
  <li>If you write code using <code>HashMap</code>s rather than <code>SparseArray</code>s your code will work with other implementations of Map and you will be able to use all of the Java APIs designed for Maps.</li>
  <li>If you write code using <code>HashMap</code>s rather than <code>SparseArray</code>s your code will work in non-android projects.</li>
  <li>Map overrides <code>equals()</code> and <code>hashCode()</code> whereas <code>SparseArray</code> doesn't.</li>
  </ol>
  
  <p>Yet whenever I try to use a <code>HashMap</code> with integer keys in an Android project, IntelliJ tells me I should use a <code>SparseArray</code> instead. I find this really difficult to understand. Does anyone know any compelling reasons for using <code>SparseArray</code>s?</p>