공통점
- 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 등으로 해결 가능 |
'Data Structure > Linear' 카테고리의 다른 글
[자료구조] 연결 리스트(Linked List) (0) | 2023.02.03 |
---|---|
[Java / 자료구조] 데크(Deque) (0) | 2023.02.01 |
[자료구조] 배열(Array) (0) | 2023.01.17 |