HashSet简单实现

来源:互联网 发布:廖雪峰python教程视频 编辑:程序博客网 时间:2024/06/05 20:39
package com.yys.student;import java.util.HashMap;/** * Created by yys on 2017/5/11. */public class SxtHashSet {    HashMap map;    private static final Object PRESENT = new Object();    SxtHashSet(){        map = new HashMap();    }    public int size(){        return map.size();    }    public void put(Object o){        map.put(o,PRESENT);//set的不重复就是利用了map里面键对象不可重复    }    public static void main(String args[]){        SxtHashSet hashSet = new SxtHashSet();        hashSet.put("aaa");        hashSet.put(new String("aaa"));        System.out.println(hashSet.size());    }}
0 0
原创粉丝点击