研究HashSet add方法在底层的作用
发布时间
阅读量:
阅读量
【
HashSet中的add方法
相关代码示例如下:
> 1. public boolean add(E e) {
>
> 2. return map.put(e, PRESENT)==null;
>
> 3. }
>
>
>
>
> ```
从源代码(HashSet类中的add方法)可以发现,PRESENT是一个常量类型(由final修饰且全部为大写字母),而map变量的类型为HashMap:
1. private transient HashMap<E,Object> map;
2. 3. private static final Object PRESENT = new Object(); 4. 5. public HashSet() { 6. map = new HashMap<>(); 7. }
> 1. public HashMap() {
>
> 2.
全部评论 (0)
还没有任何评论哟~
