So, I'm supposed to use SparseArray instead of HashMap for the sake of performance:
However, SparseArray
isn't a part of JCF and does not implement Collection
nor List
nor Map
. HashMap
, on the other hand, implements Map
and provides values()
that I can work with when needing JCF-compatible behavior. For example, using it in an ArrayAdapter
and various custom sorting (for values).
My question is three-fold:
- Why doesn't
SparseArray
implement JCF interfaces? I mean, what is the motivation for not implementing these interfaces in light of the fact that most of the methods are already there? - Are there alternatives to
SparseArray
that implement JCF interfaces or can easily be converted and retain theSparseArray
performance? - Are
HashMap
s with a few hundred elements really that much slower? Are my users really going to notice?
I'm looking for answers with depth and I prefer to have references to authoritative sites. If you think you know why SparseArray
was not implemented with JCF interfaces, show some support, help me understand. If you think I should be using SparseArray
, show me how to use it with ArrayAdapter
and custom sorting (Comparator-esque solutions preferred). If there are better alternatives, links to the API doc, library or tutorial would be helpful. If you think I should stick with HashMap
s, explain why the performance benefit of SparseArray
is outweighed by the needs of the interfaces.