I usually project development necessary framework
- The strongest network request Net on Android
- The strongest list on Android (including StateLayout) BRV
- Android’s strongest default page StateLayout
- JSON and long text log printing tool LogCat
- Supports asynchronous and global customization of the toast tool Tooltip
- Develop the debugging window tool DebugKit
- One line of code creates the transparent StatusBar StatusBar
Android has its own implementation of commonly used collections; The main purpose is to reduce memory consumption (the client does not require high data volume but as low as possible for memory);
The three collection application scenarios mentioned below are
- Up to 1000, not a lot of data (binary lookup defect), because Android basically doesn’t involve a lot of data, so it can be widely used;
- Memory optimization
- All indexes are supported (something that Maps and sets in Java do not have)
SparseArray
This collection type can avoid automatic boxing and reduce memory consumption; For a large number of data performance is not as good as the Map collection provided by Java (binary query flaw);
Two arrays are maintained inside the collection; One is for key and the other is for value.
- SparseArray
- SparseIntArray
- SparseLongArray
- SparseBooleanArray
SparseArray supports generics (custom Value types)
SparseIntArray these are collections that avoid auto-boxing and only support fixed base types; But they only support keys of type int, and do not support iterator traversal;
A function of SparseArray
SparseArray<E> clone(a)
/ / query
E get(int key)
E get(int key, E valueIfKeyNotFound)
// If no query is found, -1 is returned
int indexOfKey(int key)
int indexOfValue(E value)
// If no query is found, the default value is returned
E valueAt(int index)
int keyAt(int index)
/ / add
void append(int key, E value)
void put(int key, E value)
void setValueAt(int index, E value)
/ / delete
void delete(int key)
void remove(int key)
void removeAt(int index)
void removeAtRange(int index, int size)
void clear(a)
int size(a)
String toString(a)
Copy the code
SparseArray has some of the same functions, such as delete and remove; Both functions have exactly the same function;
SetValueAt is a function that adds a value to a collection without adding a key, but does not end up in toString (and does not affect size); Get () also does not get value;
But you can get a value from valueAt(); SparseArray does this. SparseIntArray does not support setValueAt().
ArrayMap
This collection type and SparseArray are also based on binary query. Google recommends the use of large amounts of data within a thousand, but the performance of large amounts of data is also poor.
And this collection type does not solve the auto-boxing problem, but can also reduce memory consumption;
SparseArray is a type that supports custom keys;
increase
V put(K key, V value)
void putAll(ArrayMap<? extends K, ? extends V> array)
void putAll(Map<? extends K, ? extends V> map)
V setValueAt(int index, V value)
Copy the code
delete
V remove(Object key)
boolean removeAll(Collection
collection)
V removeAt(int index)
void clear(a)
Copy the code
The query
V get(Object key)
K keyAt(int index)
V valueAt(int index)
int indexOfKey(Object key)
boolean isEmpty(a)
Copy the code
There is no indexOfValue ()
traverse
Collection<V> values(a)
Set<K> keySet(a)
Set<Entry<K, V>> entrySet(a)
Copy the code
other
boolean containsAll(Collection
collection)
boolean containsKey(Object key)
boolean containsValue(Object value)
void ensureCapacity(int minimumCapacity)
boolean equals(Object object)
int hashCode(a)
boolean retainAll(Collection
collection)
int size(a)
String toString(a)
Copy the code
ArraySet
This collection is similar to ArrayMap, except that it is not a mapping; ArraySet supports iterators;