What is the difference between ArrayMap vs HashMap?

Technology CommunityCategory: AndroidWhat is the difference between ArrayMap vs HashMap?
VietMX Staff asked 3 years ago

ArrayMap is a generic key->value mapping data structure that is designed to be more memory efficient than a traditional Java HashMap. It keeps its mappings in an array data structure — an integer array of hash codes for each item, and an Object array of the key/value pairs. This allows it to avoid having to create an extra object for every entry put into the map, and it also tries to control the growth of the size of these arrays more aggressively (since growing them only requires copying the entries in the array, not rebuilding a hash map).

That this implementation is not intended to be appropriate for data structures that may contain large numbers of items. It is generally slower than a traditional HashMap since lookups require a binary search and add and removes require inserting and deleting entries in the array. For containers holding up to hundreds of items, the performance difference is not significant, less than 50%.