当前位置:网站首页>集合之HashSet
集合之HashSet
2022-07-21 15:37:00 【51CTO】
1、简介
HashSet是底层为哈希表实现的一个集合框架。
2、层次结构
3、特性
1、不允许有重复的值,体现了元素的唯一性。
2、允许有null。
3、元素排列的无序性。
4、恒定的时间复杂度。
5、线程不安全。
输出的顺序和存入的顺序可能不一致,但每个元素在内存中的位置是固定的
无序的原因:在内存中有个哈希表,里面会有很多的元素位置,hashset对象对根据添加进来的值调用hashCode方法返回一个索引值,
根据这个索引值找到哈希表中的一个位置,存入元素.每次相同的值调用hashCode返回的索引值是固定的
不能重复: 可以存入null但null也不能重复.
怎么实现不能重复的呢?
1.先根据hashCode算是不是在同一个索引的位置.
2.如果在同一个位置再调用equals方法判断是不是同一个对象(或是不是相同的值)。
4、代码实例
更多关注
边栏推荐
- 自定义类加载器实现
- 可视化之基础设置
- 【log4j.properties完整配置,适合刚入门】
- After uniapp sets tabbar jump, other pages jump to the home page (sorting)
- Jmeter安装与设置(一)
- Vlookup function
- Matlab GUI programming skills (XI): axes/geoaxes/polaraxes drawing to create GUI coordinate area
- [a simple and clean log4j.properties complete configuration]
- 非参数检验
- MySQL 将字符串转换为数字类型并进行排序
猜你喜欢
Spirng之注解使用
Keras深度学习实战——基于ResNet模型实现性别分类
JMeter installation and setting (I)
Keras深度学习实战(11)——可视化神经网络中间层输出
20、shell编程之变量
[email protected]"/>
ZBar项目简介及安装配置 | [email protected]
"New energy + energy storage" starts from the digital twin, Tupu will make smart power to the extreme
Keras deep learning practice (12) -- facial feature point detection
Nonparametric test
Observer mode and publish / subscribe mode
随机推荐
元气森林:确实在研发不含防腐剂的无糖可乐味产品
CodeSys中编程实现串口通讯【基于树莓派4B】
Keras深度学习实战(12)——面部特征点检测
Piecemeal knowledge - Business
ligerui 表格控件grid 根据内容更改行(单元格)颜色
[log4j.properties configuration full version]
Keras' deep learning practice -- gender classification based on RESNET model
[a simple and clean log4j.properties complete configuration]
重写与重载
Stack implementation of array structure
"New energy + energy storage" starts from the digital twin, Tupu will make smart power to the extreme
124二叉树中的最大路径和
Rewriting and overloading
String说明
mysql中的字段如何选择合适的数据类型呢?
IO model, multiplexing
Matlab GUI programming skills (x): UI figure function to create a visual window
awvs安装及问题解决
码蹄集 - MT2095 · 曲径折跃
How to add a map to a page