码迷,mamicode.com
首页 > 编程语言 > 详细

java.util.HashSet

时间:2017-12-29 15:19:00      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:through   fas   nbsp   turn   padding   contains   intern   perl   res   

Operations Time Complexity Notes
add, remove, contains, size O(1) assuming the hash functions has dispersed the elements properly among the buckets
iteration proportional to the number of the elememts and buckets do not set the initial capacity too high(or the load factor too low) for the iteration-critical program
  • Implementing the java.util.Set interface, internally backed by a java.util.HashMap instance(permitting null values).
  • Making no guarantees to the iteration order and the constantness of the order over time either.
  • Not synchronized; must be synchronized externally, for example: Set s =  Collections.synchronizedSet(new HashSet());
  • Iterators returned by the iterator() method are fail-fast: it will throw a ConcurrentModificationException if the set is modified after the creation of the iterator and by any method except through the iterator‘s remove() method. Notice that the fail-fast behavior cannot be guaranteed because nothing can be guaranteed in the presence of unsynchronized concurrent modification.

 

  1. 实现了java.util.Set接口,内部由java.util.Map示例实现(允许null值)
  2. 不保证迭代顺序,也不保证迭代顺序一直不变
  3. 非同步;必须从外部同步,比如:Set s = Collections.synchronizedSet(new HashSet());
  4. iterator()返回的iterator是fail-fast的:如果这个iterator创建以后,这个set被修改了(不是这个iterator的remove()方法修改的),那么会抛出ConcurrentModificationException异常。(注意,这个fail-fast也是无法保证的,因为在非同步的并发修改中,没有什么是可以保证的)

 

 

java.util.HashSet

标签:through   fas   nbsp   turn   padding   contains   intern   perl   res   

原文地址:https://www.cnblogs.com/huangzejun/p/8143374.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!