谈谈源码中的SparseArray
谈谈源码中的SparseArray 在Andorid的源码和第三方库中,偶尔能看到该类,我们先来看一下官方文档的说明如下: SparseArray map integers to Objects. Unlike a normal array of Objects,there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping. 上面的意思是SparseArray 用来替代HashMap Int到Object的这种关系。 它设计的目的是为了比HashMap更加节省内存,这是因为: 它避免了键值的自动装箱 他的数据结构不需要依赖额外的对象来完成映射。 Note that this container keeps its mappings in an array data structure,using a binary search to find keys. The