on
[Java] Map 사용하기 - key, value, HashMap
[Java] Map 사용하기 - key, value, HashMap
주제
Map 사용하기
Interface Map
함수
put(key, value)
: 데이터를 넣을때 사용함
get(key)
: 데이터를 가져올때 사용함
Class HashMap
사용법
여기서는 key, value를 모두 String로 사용한다.
// Map Map map = new HashMap(); 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
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
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
from http://withthisclue.tistory.com/534 by ccl(A) rewrite - 2021-12-25 09:27:23