주제
Map 사용하기
Interface Map<Object, Object>
함수
put(key, value)
: 데이터를 넣을때 사용함
get(key)
: 데이터를 가져올때 사용함
Class HashMap<Object, Object>
사용법
여기서는 key, value를 모두 String로 사용한다.
// Map
Map<String, String> map = new HashMap<String, String>();
map.put("spring", "봄");
map.put("summer", "여름");
map.put("autumn", "가을");
map.put("winter", "겨울");
System.out.println("spring: " + map.get("spring"));
System.out.println("summer: " + map.get("summer"));
System.out.println("autumn: " + map.get("autumn"));
System.out.println("winter: " + map.get("winter"));
/*
// 출력 결과
spring: 봄
summer: 여름
autumn: 가을
winter: 겨울
*/
출처
Oracle Java
Interface Map<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
Modifier and Type | Method and Description |
V | get(Object key) Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key. |
V | put(K key, V value) Associates the specified value with the specified key in this map (optional operation). |
https://docs.oracle.com/javase/8/docs/api/java/util/Map.html
Class HashMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
728x90
'etc' 카테고리의 다른 글
[Java] java.lang.NumberFormatException: For input string - MAX_VALUE 2,147,483,647 (1) | 2022.12.08 |
---|---|
[notepad++] Windows 사용 중 .bak 파일이 자동으로 만들어 지는 이유, 중지하기 (0) | 2022.03.04 |
[Java] 문자열에서 원하는 단어 찾기 - indexOf() (0) | 2021.12.18 |
[Python] int(), String을 int로 바꿀때 에러 - SyntaxError: invalid token (0) | 2020.10.29 |
[Java] 현재 시간 한 줄로 표현하기 - SimpleDateFormat(), System.currentTimeMillis() (0) | 2020.09.10 |