Java Collections Cheatsheet
Quick reference for Java collections: List, Set, Map, Queue, Deque, and utility methods.
| Item | Description | Example | Category |
|---|---|---|---|
| ArrayList | Resizable array implementation | List<String> list = new ArrayList<>(); | List |
| LinkedList | Doubly linked list | List<Integer> ll = new LinkedList<>(); | List |
| Vector | Thread-safe dynamic array | Vector<String> v = new Vector<>(); | List |
| HashSet | Unordered, unique elements | Set<String> hs = new HashSet<>(); | Set |
| LinkedHashSet | Insertion-ordered set | Set<Integer> lhs = new LinkedHashSet<>(); | Set |
| TreeSet | Sorted set | Set<String> ts = new TreeSet<>(); | Set |
| HashMap | Key-value hash map | Map<Integer,String> map = new HashMap<>(); | Map |
| LinkedHashMap | Insertion-ordered map | Map<String,Integer> lhm = new LinkedHashMap<>(); | Map |
| TreeMap | Sorted map by keys | Map<Integer,String> tm = new TreeMap<>(); | Map |
| PriorityQueue | Min-heap or custom comparator | Queue<Integer> pq = new PriorityQueue<>(); | Queue |
| ArrayDeque | Resizable deque (stack/queue) | Deque<String> dq = new ArrayDeque<>(); | Deque |
| Collections | Utility class for sorting/shuffling | Collections.sort(list); Collections.shuffle(list); | Utility |
| Arrays | Utility class for array operations | Arrays.asList(1,2,3); Arrays.sort(arr); | Utility |