When to use Android's ArrayMap instead of a HashMap?

后端 未结 3 698
别那么骄傲
别那么骄傲 2021-01-05 04:53

Android have their own implementation of HashMap, which doesnt use Autoboxing and it is somehow better for performance (CPU or RAM)?

https://developer.android.com/re

3条回答
  •  灰色年华
    2021-01-05 05:44

    ArrayMap uses way less memory than HashMap and is recommended for up to a few hundred items, especially if the map is not updated frequently. Spending less time allocating and freeing memory may also provide some general performance gains.

    Update performance is a bit worse because any insert requires an array copy. Read performance is comparable for a small number of items and uses binary search.

提交回复
热议问题