java.util.HashSet
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.
- 实现了java.util.Set接口,内部由java.util.Map示例实现(允许null值)
- 不保证迭代顺序,也不保证迭代顺序一直不变
- 非同步;必须从外部同步,比如:Set s = Collections.synchronizedSet(new HashSet());
- iterator()返回的iterator是fail-fast的:如果这个iterator创建以后,这个set被修改了(不是这个iterator的remove()方法修改的),那么会抛出ConcurrentModificationException异常。(注意,这个fail-fast也是无法保证的,因为在非同步的并发修改中,没有什么是可以保证的)
java.util.HashSet的更多相关文章
- 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> ...
- 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> ...
- JDK 8 - java.util.HashSet 实现机制分析
JDK 8 Class HashSet<E> Doc: public class HashSet<E> extends AbstractSet<E> impleme ...
- java.util.HashSet源码分析
public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java. ...
- JDK1.8源码(八)——java.util.HashSet 类
在上一篇博客,我们介绍了 Map 集合的一种典型实现 HashMap ,在 JDK1.8 中,HashMap 是由 数组+链表+红黑树构成,相对于早期版本的 JDK HashMap 实现,新增了红黑树 ...
- Java的HashSet类
如果要查找一个集合中是否包含了某个对象,那么就需要把这个对象和这个集合中的每个对象依次进行比较和判断,直到找到这个对象为止,或者把所有对象都比较一次为止(如果最后一个对象才是要查找的对象,或者集合中没 ...
- 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 ...
- 软件包 java.util 的分层结构
概述 软件包 类 使用 树 已过时 索引 帮助 JavaTM Platform Standard Ed. 6 上一个 下一个 框架 无框架 所有类 ...
- Java之hashSet实现引用类型的禁止重复功能
题目:在HashSet集合中添加Person对象,把姓名相同的人当作同一个人,禁止重复添加. 分析:1.定义一个Person类,定义name和age属性,并重写hashCode()和equals()方 ...
随机推荐
- zzuli 1816: 矩形 排序思维
1816: 矩形 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 179 Solved: 54 SubmitStatusWeb Board Descr ...
- zzuli 1815: easy problem 打表
1815: easy problem Time Limit: 1 Sec Memory Limit: 128 MB Submit: 243 Solved: 108 SubmitStatusWeb ...
- 第四届河南省ACM 表达式求值 栈
表达式求值 时间限制: 1 Sec 内存限制: 128 MB 提交: 14 解决: 7 [提交][状态][讨论版] 题目描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简 ...
- upload 上传类
<?php/**file: fileupload.class.php 文件上传类FileUpload本类的实例对象用于处理上传文件,可以上传一个文件,也可同时处理多个文件上传 */class U ...
- ThinkPHP5.0 实现 app支付宝支付功能
前几天做项目,要求要用到支付宝接口,第一次做,弄了好几天 各种坑啊,简单写一下我做支付宝支付的过程,希望对也是第一次做支付宝支付的童鞋有帮助, 不懂的可以先去支付平台看一下支付宝支付的文档,我是下的d ...
- python处理csv文件问题解决贴
实际工作中,碰到这么个问题:有个软件跑在linux系统上,其中用到一个数据库是csv格式的,但要向这个数据库添加600行新的数据,数据源同样是一个csv格式的文件. 有了目标,开始干活.首先想到的是, ...
- 基于 HTML5 Canvas 的 3D 压力器反序列化
在实际应用中,我觉得能够通过操作 JSON 文件来操作 3D 上的场景变化是非常方便的一件事,尤其是在做编辑器进行拖拽图元并且在图元上产生的一系列变化的时候,都能将数据很直观地反应给我们,这边我们简单 ...
- HTMLCSS实现左侧固定宽度右侧内容可滚动
在做移动端页面的时候,经常会碰到一个div中分左右两个div,左侧div固定宽度或百分比,右侧div中内容左右溢出,需要左右滑动才可以浏览到全部内容,为此写了一个demo. 处理这个问题的核心关键点是 ...
- DotNetCore跨平台~xUnit生成xml报告
在CI/CD流行至极的今天,你的项目没有自动化测试绝对是不可以接受的,在进行自动化部署和持续集成时,我们的dotnet core项目也是可以实现自动化的,之前说过gitlab,jenkins对持续集成 ...
- hdu4893 Wow! Such Sequence!
线段树结点上保存一个一般的sum值,再同一时候保存一个fbsum,表示这个结点表示的一段数字若为斐波那契数时的和 当进行3操作时,仅仅用将sum = fbsum就可以 其它操作照常进行,仅仅是单点更新 ...