ArrayMap VS HashMap

1.ArrayMap和HashMap概况

  • HashMap:采用数组和链表模式存储数据。
    ArrayMap:采用一个hashcode数组和一个数组对象存储数据。数组偶数为key,奇数为value。

2.两者不同

  • 存储方式不同
    HashMap采用数组和链表模式存储数据。
    ArrayMap采用一个hashcode数组和一个数组对象存储数据。
  • 扩容方式不同
    HashMap是新new一个对象。
    ArrayMap是copy,比HashMap更加节省内存。
  • 查找方式不同
    HashMap是利用迭代器。
    ArrayMap是利用二分查找法。
  • 收缩不同
    HashMap 去掉元素后无法收缩。
    ArrayMap 提供了数组收缩,在去掉元素后能够收缩数组。

你可能感兴趣的:(ArrayMap VS HashMap)