algorithm/정리

자바 기본 자료구조 선언 정리

ssoheeh 2024. 4. 9. 21:59

자바를 오랜만에 써서 기본 자료구조를 선언하는 방법이 헷갈리는 본인을 위한 정리

 

map

Map<String, String> map = new HashMap<>();
SortedMap<String, Integer> sortedMap = new TreeMap<>();

 

 

queue

Queue<자료형> q = new LinkedList<>();
Queue 변수명 = new LinkedList(); //다른 자료형 넣기 가능

// 기본형: 우선순위가 낮은 숫자가 먼저 나옴 (작은 숫자)
PriorityQueue<Integer> pQ = new PriorityQueue<>(); 
// 우선순위가 높은 숫자가 먼저 나옴 (큰 숫자)
PriorityQueue<Integer> pQ = new PriorityQueue<>(Collections.reverseOrder());

 

 

stack

Stack<Integer> stackInt = new Stack<>();

 

 

 

deque

Deque<String> dq = new ArrayDeque<>();

 

'algorithm > 정리' 카테고리의 다른 글

재귀  (0) 2024.04.11
BFS  (0) 2024.04.10
그리디 알고리즘  (0) 2024.04.09
DP (다이나믹 프로그래밍)  (0) 2024.04.08
이분탐색 추가 - Upper Bound(상한), Lower Bound(하한)  (0) 2024.04.08