Java ã® HashSet ã®ã¢ã«ã´ãªãºã ã確èªãããã¨ã¯ã©ã¹ã®ä¸èº«ãè¦ã¦ã³ã£ããã
HashSet ã¯ãå¦çã®ã»ã¨ãã©ã HashMap ã¸å§è²ããã ãã¨ããè¶
ç°¡åãªã¢ã«ã´ãªãºã ã§ããã
ã³ã³ã¹ãã©ã¯ã¿ã¯ãããªæãã
public HashSet() { map = new HashMap<E,Object>(); }
ã¡ã½ããã®å¦çã¯ï¼
public boolean add(E e) { return map.put(e, PRESENT)==null; }
å¼æ°ã KeyãPRESENT ã¨ããããã¼ã®ãªãã¸ã§ã¯ãã Value ã¨ãã¦ãMap ã«è¦ç´ ã追å ãã¦ãã¾ããã
contains ã iterator ã¨ãã£ãã¡ã½ãããããã®ã¾ã¾ Map ã¸å¦çãå§è²ãã¦ããã ãã«ãªã£ã¦ãã¾ããã
ä»ã®å®è£ ã¯ï¼
ä»ã® TreeSet ã EnumSet ãã対ã«ãªã TreeMap ã EnumMap ã¸å¦çãå§è²ãã¦ãã¾ããã
HashMap åæ§ã«ãã©ã®ã¯ã©ã¹ãä¸èº«ã¯ã»ã¨ãã©ç©ºã£ã½ã§ãã½ã¼ã¹ã®åå以ä¸ãAPIã®è¨è¿°ã«ãªã£ã¦ãã¾ãã*1ã
å§è²ã®ãææ¬
ããã¯ãå§è²ã®ãããææ¬ã ã¨æãã¾ãã
ããã¾ã§ä½ããã¦ããªãã¯ã©ã¹ã£ã¦ããã®ã¯ãèªãã§ãã¦ãããæ°é®®ã§ããã
ã¡ãªã¿ã«ããã®ãããªå®è£ ã«ãªã£ã¦ãããã¨ã¯ãAPIã«ããããªãæ¸ãã¦ããã¾ãã*2ã
ãã®ã¯ã©ã¹ã¯ãããã·ã¥ãã¼ãã« (å®éã«ã¯ HashMap ã®ã¤ã³ã¹ã¿ã³ã¹) ã«é£åããSet ã¤ã³ã¿ãã§ã¼ã¹ãå®è£ ãã¾ãã
Oracle Technology Network for Java Developers | Oracle Technology Network | Oracle