์๋ฐ Map ์์ฃผ ์ฐ๋ ๋ฉ์๋ ์ ๋ฆฌ
๊ฐ ๋ฃ๊ธฐ & ๊ฐ์ ธ์ค๊ธฐ put() / get(key) Map map = new HashMap(); map.put("์์", 10); map.put("์ฑ
์", 5); map.put("๋ฉํฐํญ", 3); int val = 0; val = map.get("์์");// 10 val = map.get("์ฑ
์");// 5 val = map.get("๋ฉํฐํญ");// 3 ํค๊ฐ ์์ผ๋ฉด ๊ฐ ๋ฐํ, ์์ผ๋ฉด ๊ธฐ๋ณธ ๊ฐ ๋ฐํ getOrDefault(key, default) String[] alphabet = {"A", "B", "C" ,"A"}; Map map = new HashMap(); for (String key : alphabet) { map.put(key, map.getOrDefault(key, 0) + 1); } // ..
2021. 11. 2.