SparseArray VS ArrayList的区别? [英] Difference between SparseArray Vs ArrayList?

查看:1160
本文介绍了SparseArray VS ArrayList的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道SparseArray和ArrayList,哪一个是更好地利用之间的性能和效率的置疑。 我不能undestand何时使用SparseArray时的ArrayList

i want to know performance and efficency between SparseArray and ArrayList and which one is better to use. i can't undestand when to use SparseArray and when ArrayList

推荐答案

SparseArray 是为了节省内存,如果你有,有很多的列表的目的差距。如果你只得到了10个项目,并对其进行索引范围从0到1000的数字,那么的ArrayList 将有大量的的在这空项,这将是非常浪费的。 A SparseArray 将使用数据结构内部,以避免这样的问题。

The purpose of a SparseArray is to save memory if you've got a list that has lots of gaps in. If you've only got 10 items, and the numbers that index them range from 0 to 1000, then an ArrayList will have lots of null entries in it, and that will be quite wasteful. A SparseArray will use data structures internally to avoid that problem.

在这种情况下,另一种是的HashMap ,这比 SparseArray 如果你有很多更好的项目。

The alternative in this situation is a HashMap, which is better than a SparseArray if you've got lots of items.

的实施并不意为适合于数据结构,可能包含大量项目。它通常比传统的HashMap慢,中,由于查找需要二进制搜索和添加和删除需要插入和删除数组中的条目。用于容器保持高达数百个项目,其性能不同的是不显著,小于50%的

The implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap, since lookups require a binary search and adds and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.

Android开发文档

这篇关于SparseArray VS ArrayList的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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