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的更多相关文章

  1. java.util.HashSet, java.util.LinkedHashMap, java.util.IdentityHashMap 源码阅读 (JDK 1.8)

    一.java.util.HashSet 1.1 HashSet集成结构 1.2 java.util.HashSet属性 private transient HashMap<E,Object> ...

  2. java.util.HashSet, java.util.LinkedHashMap, java.util.IdentityHashMap 源码阅读 (JDK 1.8.0_111)

    一.java.util.HashSet 1.1 HashSet集成结构 1.2 java.util.HashSet属性 private transient HashMap<E,Object> ...

  3. JDK 8 - java.util.HashSet 实现机制分析

    JDK 8 Class HashSet<E> Doc: public class HashSet<E> extends AbstractSet<E> impleme ...

  4. java.util.HashSet源码分析

    public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java. ...

  5. JDK1.8源码(八)——java.util.HashSet 类

    在上一篇博客,我们介绍了 Map 集合的一种典型实现 HashMap ,在 JDK1.8 中,HashMap 是由 数组+链表+红黑树构成,相对于早期版本的 JDK HashMap 实现,新增了红黑树 ...

  6. Java的HashSet类

    如果要查找一个集合中是否包含了某个对象,那么就需要把这个对象和这个集合中的每个对象依次进行比较和判断,直到找到这个对象为止,或者把所有对象都比较一次为止(如果最后一个对象才是要查找的对象,或者集合中没 ...

  7. Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill

    异常信息如下: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value ...

  8. 软件包 java.util 的分层结构

    概述  软件包  类  使用   树  已过时  索引  帮助  JavaTM Platform Standard Ed. 6  上一个   下一个 框架    无框架    所有类         ...

  9. Java之hashSet实现引用类型的禁止重复功能

    题目:在HashSet集合中添加Person对象,把姓名相同的人当作同一个人,禁止重复添加. 分析:1.定义一个Person类,定义name和age属性,并重写hashCode()和equals()方 ...

随机推荐

  1. 01.redis初识

    Redis学习: redis是什么? Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 不过Redis在生产环境中使用最多的功能是缓存系统.至于其 ...

  2. html5 实现 文件夹上传

    先插个背景:最近所在项目有个小需求,就是上传文件要可以同时选择文件夹及文件,然后把文件夹内得文件及所选单文件全部选择上传,借助于搜索关键词没搜到想要的结果(相关文章貌似很好,要么就是遍历文件夹内的文件 ...

  3. 【微服务】之四:轻松搞定SpringCloud微服务-负载均衡Ribbon

    对于任何一个高可用高负载的系统来说,负载均衡是一个必不可少的名称.在大型分布式计算体系中,某个服务在单例的情况下,很难应对各种突发情况.因此,负载均衡是为了让系统在性能出现瓶颈或者其中一些出现状态下可 ...

  4. 《Linux命令行与shell脚本编程大全》第二十二章 gawk进阶

    gawk是一门功能丰富的编程语言,你可以通过它所提供的各种特性来编写好几程序处理数据. 22.1 使用变量 gawk编程语言支持两种不同类型的变量: 内建变量和自定义变量 22.1.1 内建变量 ga ...

  5. poj 2769 Reduced ID Numbers 同余定理

    链接:http://poj.org/problem?id=2769 题意:寻找数m,是的对于n个数的余数不同 思路:暴力,优化:同余部分不用测试 代码: #include <iostream&g ...

  6. day2、Linux别名

    Linux中修改配置别名 ####用到的命令: alias是用来查看系统中有什么别名 source 让配置生效 临时取消别名的方法 unalias 临时取消别名 \cp /mnt/test.txt / ...

  7. Qt快速上手(学习笔记四)

    拖了大半年,今天终于有更新了...我自己都不好意思,最近太忙了! 今天讲一下:QML语法 一 概述 QML是一种专门用于构建用户界面的编程语言,它允许用户构建高性能,具有流畅特效的可视化应用程序,QM ...

  8. codeforces 558 E A Simple Task

    题目大意就是给一个字符串,然后多个操作.每次操作能够把每一段区间的字符进行升序或者降序排序,问终于的字符串是如何的. 做法的话就是用线段树维护区间和 一開始仅仅考虑字符串中字符'a'的情况.如果操作区 ...

  9. 浏览器正确理解和使用GBK及UTF-8(UTF-8 + BOM)网页编码

    网页编码英文译为web page encoding.是在网页中指定其特定的字符编码格式的库. GBK是国家标准GB2312基础上扩容后兼容GB2312的标准. GBK的文字编码是用双字节来表示的.即不 ...

  10. 几条jQuery代码片段助力Web开发效率提升

    平滑滚动至页面顶部 以下是jQuery最为常见的一种实现效果:点击一条链接以平滑滚动至页面顶部.虽然没什么新鲜感可言,但每位开发者几乎都用得上. $("a[href='#top']" ...