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()); } }
HashSet简单实现
最新推荐文章于 2021-11-16 16:09:44 发布