<Type> tells the compiler what's stored — catches type errors early| Primitive | Wrapper |
|---|---|
int | Integer |
double | Double |
boolean | Boolean |
char | Character |
Integer i = 5; (int → Integer, automatic)int n = i; (Integer → int, automatic)ArrayList — fast random access, resizable arrayLinkedList — fast insert/remove at endsIteratorQueue is FIFO by default; PriorityQueue instead always returns its smallest (or highest-priority, via a Comparator) element first from poll().
Each key's hashCode() determines a "bucket" to store it in — giving average O(1) add/remove/lookup for HashSet/HashMap.
Quick, safe way to create a fixed, read-only collection — useful for constants or data that should never change after creation.
Standard collections (ArrayList, HashMap) are not safe when multiple threads modify them at once — can corrupt data or throw ConcurrentModificationException.
ConcurrentHashMap — thread-safe mapCopyOnWriteArrayList — thread-safe list for read-heavy usejava.util.concurrent| Method | Purpose |
|---|---|
add(item) | append |
get(i) | read at index |
remove(i) | remove at index |
indexOf(item) | first index, or -1 |
size() | element count |
| Method | Purpose |
|---|---|
add(item) | adds if not already present |
contains(item) | membership test |
remove(item) | removes by value |
size() | element count |
| Method | Purpose |
|---|---|
put(k,v) | insert/update a pair |
get(k) | value for key, or null |
containsKey(k) | true if key exists |
keySet()/values() | all keys / all values |
remove(k) | deletes the pair |