
List 자료구조 : https://backendeveloper.tistory.com/24
Queue 자료구조 : https://backendeveloper.tistory.com/25
HashTable 자료구조 : https://backendeveloper.tistory.com/28
HashMap<String,Integer> map = new HashMap<>(); // 선언
HashMap<String,Integer> map2 = new HashMap<>(map); // map 복사
HashMap<String,Integer> map3 = new HashMap<>(10); // 크기 지정
// 값 추가
map.put("Java", 1);
map.put("C++", 2);
map.remove("Java"); // Key(Java)에 해당하는 값 제거
map.clear(); // HashMap의 모든 값 제거
map.replace("Java", 10); // Key에 해당하는 Value 변경
map.isEmpty(); // HashMap이 비어있다면 true
map.get("Java"); // Key(Java)에 해당하는 Value(1) 리턴
map.containsKey("Java"); // Key값에 포함되면 true
map.containsValue(1); // Value에 포함되면 true
map.keySet(); // Key값들 리턴[Java, C++]
map.values(); // Value들 리턴[1, 2]
map.getOrDefault("key", defaultValue); // "key"에 해당하는 값이 없으면 defaultValue 반환
Priority Queue
// 선언
PriorityQueue<Integer> pq = new PriorityQueue<>(); // 오름차순
PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(Collections.reverseOrder()); // 내림차순
// 값 추가
pq.add(1);
pq.offer(2);
pq.poll(); // top 값 출력 후 제거
pq.remove(); // top 값 제거
pq.clear(); // 우선순위큐 초기화
pq.peek(); // top 값 출력
pq.isEmpty() // 우선순위큐가 비어있으면 true
'Algorithm' 카테고리의 다른 글
| 이진 탐색 트리 자료구조 (1) | 2023.03.28 |
|---|---|
| 트리 (0) | 2023.03.27 |
| 해시 테이블 자료구조 (0) | 2023.03.27 |
| Queue 자료구조 (1) | 2023.03.27 |
| List 자료구조 (2) | 2023.03.24 |