Warning shows when i use Hash Map In android(Use new SparseArray)

后端 未结 4 1371
不知归路
不知归路 2021-01-30 03:01

I am new to developing in android. In my android app I\'m using HashMap, but I\'m getting a warning:

**\"Use new SparseArray(...) ins         


        
4条回答
  •  醉梦人生
    2021-01-30 03:41

    SparseArray is used when you are using an Integer as a key.

    When using the SparseArray, the key will stay as a primitive variable at all times unlike when you use the HashMap where it is required to have a Object as a key which will cause the int to become an Integer object just for a short time while getting the object in the map.

    By using the SparseArray you will save the Garbage Collector some work.

    So use just like a Map.

提交回复
热议问题