android Google推荐的容器SparseArrayCompat简介

private static SparseArrayCompat<BaseFragment>  mCaches = new SparseArrayCompat<BaseFragment>();
mCaches.put(xx);
mCaches.get(xx);
  • 优点节省最高50%缓存;
    SparseArrayCompat()其实是一个map容器,它使用了一套算法优化了hashMap,可以节省至少50%的缓存.
  • 缺点但是有局限性只针对下面类型.
    • key: Integer; value: object

因此当HshMap()的key是Integer类型时推荐使用SparseArrayCompat(),用法与Map相似.
如下格式:

private static HashMap<Integer, Fragment> mCaches = new HashMap<Integer, Fragment>();  
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐