java.util.Set中的重复元素 [英] Duplicate elements in java.util.Set

查看:108
本文介绍了java.util.Set中的重复元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.util.Set 实现删除重复元素。

如何在内部删除重复元素 java.util.Set ??

How are duplicates elements deleted internally in a java.util.Set??

推荐答案

实际上来自AFAIK的来源java中的大多数 Set 实现甚至不检查元素是否已被包含。

Actually AFAIK from the sources most Set implementations in java don't even check if the element is already contained.

它们总是执行 add()在其内部结构上保存set元素并让该对象处理重复的情况。

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中的重复元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆