how sparse array differs from a hashmap in java

5.6k views Asked by At

In my Android application I have used Hash maps in many situations. And I was asked to use sparse arrays by concerning the performance of the application. So, how sparse array differs from a hashmap in java and what are the advantages of sparse array over hashmap . Thank You.

1

There are 1 answers

0
Juned Ahsan On BEST ANSWER

I beleive the description of sparse array clearly mentions the difference:

It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

For further reading: http://developer.android.com/reference/android/util/SparseArray.html