Benefits to use SparseArray over HashMap is:
· More memory efficient by using primitives
· No auto-boxing
· Allocation-free
Drawbacks:
· For large collections, it is slower
· It only available for Android
I've build a large app with it and it still worked without any issue. At the moment I couldn't tell if the memory improved that's why I keep it as a draft for now. Need to do some more testing.
While going trough some native Android optimization posts like https://medium.com/android-news/app-optimization-with-arraymap-sparsearray-in-android-c0b7de22541a I found one place where we can switch from HashMap to SparseArray
I've build a large app with it and it still worked without any issue. At the moment I couldn't tell if the memory improved that's why I keep it as a draft for now. Need to do some more testing.
https://youtu.be/ORgucLTtTDI?t=221 gives a pro/cons list when to use it or stay with the HashMap.