PriorityQueue<Integer>pQ=newPriorityQueue<>();// 삽입 (큐랑 동일)pQ.add(1);// front 확인 및 제거pQ.remove();
해시맵
HashMap<String,Integer>map=newHashMap<>();map.put("apple",1);map.put("banana",2);// 키값 변경map.put("banana",4);// 키가 있는지 확인, 키값 가져오기 (get)Stringkey="apple";if(map.containsKey(key)){intvalue=map.get(key);System.out.println(key+": "+value);// apple: 1 }// 키값 삭제map.remove("banana");
스택
Stack<Integer>stack=newStack<>();
큐
Queue<Integer>queue=newLinkedList<>();
연결리스트
LinkedList<Integer>list=newLinkedList<>();// addlist.addFirst(1);// 앞에 추가list.addLast(2);// 뒤에 추가list.add(3);list.add(1,10);// index 1에 값 "10"추가// removelist.removeFirst();list.removeLast();list.remove();// 생략시 index 0 제거list.remove(2);// index 2 제거list.clear();// 기타list.get(1);list.size();list.contain(1);// 1 검색, booleanlist.indexOf(1);// index 1에 있는 값 불러오기, 없으면 -1
해시셋
HashSet<Integer>set1=newHashSet<>();// 용량이 10인 HashSet 생성 (해시셋은 저장공간을 늘릴 때, 2배로 늘리기 때문에 크기를 알고 있다면 정해주는 것이 Best)HashSet<Integer>set2=newHashSet<>(10);set.add(1);set.add(1);set.add(2);set.remove(1);// 값 1 제거set.clear();if(set.contains(1)){System.out.println("It has 1.");}
문자열
정렬
// 기본 정렬 (오름차순)Arrays.sort(arr);// 내림차순 정렬Arrays.sort(arr,Collections.reverseOrder());