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()); } }