HashMap与TreeMap

[size=medium]
区别:
1) HashMap是不保证里面元素顺序的,尤其是,随着时间的推移,它也不能保证顺序的不变。
This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

TreeMap是实现了SortedMap接口,是有序的,TreeMap是一颗红黑树(自平衡的二叉排序树,且节点带有颜色)

2) HashMap的基本操作get,put的时间复杂度是常数O(1),

This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.

而TreeMap的containsKey, get, put, remove操作的时间复杂度是log(n)
This implementation provides guaranteed log(n) time cost for the containsKey, get, put and remove operations. Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's Introduction to Algorithms.


[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值