--- id: java-hashmap title: "Java HashMap" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["์ž๋ฐ” HashMap"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "collections-framework", "hashmap"] raw_sources: ["https://www.w3schools.com/java/java_hashmap.asp"] applied_in: [] github_commit: "" --- # [[Java HashMap]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) Re-putting an existing key doesn't throw or create a duplicate entry โ€” it silently OVERWRITES the previous value (`put("Norway", "Oslo")` twice just keeps one "Norway"โ†’"Oslo" entry), which is the HashMap-specific version of the "keys must be unique" rule, distinct from HashSet's simple duplicate-ignore behavior since here the VALUE could actually change on overwrite. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`HashMap`** โ€” key/value storage; access by key instead of index. [S1] - **`put(key, value)`** โ€” adds a new pair OR overwrites the value if the key already exists. [S1] - **`get(key)`**, **`remove(key)`**, **`clear()`**, **`size()`** โ€” standard operations, all key-based. [S1] - **`keySet()`** vs. **`values()`** โ€” iterate keys only, or values only, in a for-each loop. [S1] - **Wrapper classes for primitive values** โ€” same rule as ArrayList/HashSet. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Overwrite on duplicate key: `capitalCities.put("Norway", "Oslo"); capitalCities.put("Norway", "Oslo"); // still one Norway entry โ€” value overwritten, not duplicated`. [S1] - Loop keys: `for (String i : capitalCities.keySet()) { System.out.println(i); }`. [S1] - Loop values: `for (String i : capitalCities.values()) { System.out.println(i); }`. [S1] - Loop keys+values: `for (String i : capitalCities.keySet()) { System.out.println("key: " + i + " value: " + capitalCities.get(i)); }`. [S1] - Integer values: `HashMap people = new HashMap(); people.put("John", 32);`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **ํ‚ค ์ค‘๋ณต ์‹œ ๊ฐ’ ๋ฎ์–ด์“ฐ๊ธฐ**: ๊ฐ™์€ ํ‚ค๋กœ ๋‹ค์‹œ put()ํ•˜๋ฉด ์ด์ „ ๊ฐ’์ด ์ตœ์‹  ๊ฐ’์œผ๋กœ ๋ฎ์–ด์จ์ง„๋‹ค๋Š” ์ ์ด ๋ช…์‹œ๋จ(ํ‚ค๋Š” ๋ฐ˜๋“œ์‹œ ์œ ์ผํ•ด์•ผ ํ•จ). [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” ๊ตญ๊ฐ€-์ˆ˜๋„ ๋งคํ•‘์ฒ˜๋Ÿผ ํ‚ค๋กœ ๊ฐ’์„ ์กฐํšŒํ•˜๋Š” ๊ฒƒ์ด ์‹ค์ „ ํ™œ์šฉ์˜ ๋Œ€ํ‘œ ์˜ˆ์‹œ๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Looping keys and values together (Java): ```java HashMap capitalCities = new HashMap(); capitalCities.put("England", "London"); capitalCities.put("Norway", "Oslo"); for (String i : capitalCities.keySet()) { System.out.println("key: " + i + " value: " + capitalCities.get(i)); } ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.90 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[Java Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[Java Map]], [[Java TreeMap]], [[Java LinkedHashMap]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** Map์˜ ๋Œ€ํ‘œ ๊ตฌํ˜„์ฒด โ€” ์ •๋ ฌ๋œ TreeMap ์ฑ•ํ„ฐ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” Java HashMap โ€” https://www.w3schools.com/java/java_hashmap.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java HashMap" page (Astra wiki-curation, P-Reinforce v3.1 format).