title: SparseArray Iterate & Remove in Android
body: <p>I'm trying to get a result from the queue, process it and remove it after. But I got Java exception in the case access null key, see below  </p>
  
  <pre><code>int key = 0;
  int size = mQueue.size();
  for (int i = 0; i&lt; size; i++) {
      key = mQueue.keyAt(i);
      result = mQueue.get(key);
      // process(result);
      mQueue.remove(result.id);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&gt;&gt;From Queue--&gt;{  
  1=Result[id=1,type-1,data],  
  5=Result[id=5,type=40,data2],  
  6=Result[id=6,type=2,data3]}
  </code></pre>
  
  <hr>
  
  <pre><code>&gt;&gt;From Loop--&gt;  
  i=1, key=1  
  i=2, key=6&lt;--- was expecting key= 5  
  i=3, key=6&lt;--- JE here, since mQueue.get(6) =null because removed from i=2
  </code></pre>
  
  <p>Is there something wrong?</p>