Duplicate elements in java.util.Set(java.util.Set 中的重复元素)
问题描述
java.util.Set 实现移除重复元素.
如何在 java.util.Set 内部删除重复元素?
How are duplicates elements deleted internally in a java.util.Set?
推荐答案
实际上,来自 java 中的大多数 Set 实现的 AFAIK 甚至都不检查元素是否已包含.
Actually AFAIK from the sources most Set implementations in java don't even check if the element is already contained.
他们只是总是在其内部结构上执行 add() 来保存集合元素并让该对象处理重复情况.
They just always execute the add() on their internal structure which holds the set elements and let that object handle the duplication case.
例如HashSet 在内部 HashMap 上调用 put(K,V),如果重复,则插入新对象覆盖旧条目.
e.g. HashSet calls put(K,V) on the internal HashMap which just inserts the new object overwriting the old entry if duplicate.
这篇关于java.util.Set 中的重复元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java.util.Set 中的重复元素
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
