When to use Android ArrayMap instead of HashMap?

Does Android have its own HashMap implementation that doesn't use Autoboxing, and does it somehow work better (CPU or RAM)?

https://developer.android.com/reference/android/support/v4/util/ArrayMap.html

From what I read here, I have to replace my HashMap objects with ArrayMap objects if I have a HashMaps that is smaller than hundreds of records in size and will often be written to. And it makes no sense to replace my HashMaps with ArrayMaps if they are going to contain hundreds of objects and will be written once and often read. Am I right?

+5
source share
3 answers

Do you have any reason for such a replacement?

If this is to improve performance, you need to take action before and after the replacement and see if the replacements have helped.

Perhaps not worth the effort.

+3
source

You should watch this video: https://www.youtube.com/watch?v=ORgucLTtTDI
Perfect situations:
1. A small number of elements (<1000) with a large number of accesses or inserts and deletions are often enough that the overhead for this is not noticed.
2. map containers - map cards in which sub-sets have a small number of items and often repeat for a longer time.

+6
source

ArrayMap uses less memory than HashMap, and is recommended for several hundred items, especially if the map is not updated frequently. Reducing the time to allocate and free memory can also provide some overall performance boost.

The performance update is a little worse because any insert requires a copy of the array. The read performance is comparable for a small number of items and uses binary search.

+3
source

Source: https://habr.com/ru/post/1233409/


All Articles