Java_HashSet工作原理

Java中的HashSet基于HashMap实现,保证元素不重复但不保证迭代顺序。它允许存储null元素,实际存储时value为固定对象。HashSet的操作主要通过HashMap的相关方法完成。
摘要由CSDN通过智能技术生成

This class implements the Set interface, backed by a hash table (actually a HashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class permits the null element.

HashSet实现了Set接口,其本质是一个HashMap,只使用到了HashMap的key值,value是一个固定的值。对HashSet进行迭代的时候,不能保证其迭代的顺序,其允许添空值。

简单例子如下:

@SuppressWarnings(value = { "all" })
public class TestHashSet {
    public static void main(String[] args) {
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值