什么时候使用Android的ArrayMap代替HashMap? [英] When to use Android's ArrayMap instead of a HashMap?

查看:109
本文介绍了什么时候使用Android的ArrayMap代替HashMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android有自己的HashMap实现,它不使用自动装箱,并且在某种程度上可以提高性能(CPU或RAM)?

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/reference/android/support/v4/util/ArrayMap.html

从我在这里阅读的内容中,如果我的HashMaps的大小低于数百个记录并且将被频繁写入,则应将我的HashMap对象替换为ArrayMap对象.而且,如果我的HashMaps将包含数百个对象并且将被写入一次并经常读取,则用ArrayMaps替换HashMaps没有任何意义.我正确吗?

From what I read here, I should replace my HashMap objects with ArrayMap objects if I have HashMaps whose size is below hundreds of records and will be frequently written to. And there is no point in replacing my HashMaps with ArrayMaps if they are going to contain hundreds of objects and will be written to once and read frequently. Am I Correct?

推荐答案

您是否有任何理由尝试进行这种替换?

Is there any reason for you to attempt such a replacement?

如果要提高性能,则必须在更换之前和之后采取措施,看看更换是否有帮助.

If it's to improve performance then you have to make measures before and after the replacement and see if the replacements helped.

可能不值得付出努力.

这篇关于什么时候使用Android的ArrayMap代替HashMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆