Data Structure/Linear
[자료구조] 해시테이블(HashTable) vs 해시맵(HashMap) 비교
Dev_Green
2023. 1. 17. 19:08
공통점
- HashTable 과 HashMap 모두 Map 인터페이스의 구현체이다.
따라서 다형성에 따라 아래와 같이 Map으로 HashTable과 HashMap 객체를 받아 올 수 있다.
// HashTable
Hashtable<Integer, Integer> ht = new Hashtable<>();
// HashMap
HashMap<Integer, Integer> hm = new HashMap<>();
Map<Integer, Integer> map1 = ht;
Map<Integer, Integer> map2 = hm;
차이점
HashTable | HashMap | |
Key에 Null 사용 가능 여부 | X | O |
Thread-Safe | O (멀티 스레드 환경에서 우수) |
X (싱글 스레드 환경에서 우수) synchronizedMap, ConcurrentHashMap 등으로 해결 가능 |