HashMaps, ArrayMaps and SparseArrays in Android
This article will show why and when to use ArrayMap and SparseArray to optimize your Android Applications. Android developers must be observing Lint warnings recently to replace some of their HashMaps with SparseArrays with a promise of memory optimization. Good for us! There are few classes we should learn to use, like ArrayMap and SimpleArrayMap. There are also multiple variants of SparseArrays. This post will describe these classes along with their internals. Let’s start with some code showing how to use these classes java. util . HashMap < String , String > hashMap = new java. util . HashMap < String , String > ( 16 ) ; hashMap. put ( "key" , "value" ) ; hashMap. get ( "key" ) ; hashMap. entrySet ( ) . iterator ( ) ; android. util . ArrayMap < String , String > arrayMap = new android. util . ArrayMap < String , String > ( 16 ) ; arrayMap. put ( "key" , "value" ) ; arrayMap. get ( ...
Comments
Post a Comment