solulubeta
Sign in
Cheat Sheets / Coding
02.02 · Cheat sheet

Java for Coding Tests

The Java collections, snippets, sorting, string methods and integer traps you need in a timed coding test.

3 min Cheat sheet Pro

Everything in Java you reach for during a timed test, and the traps that cost marks.

Which collection?

NeedUse
Growable listArrayList
Stack or queueArrayDeque
Key → valueHashMap
Unique itemsHashSet
Sorted keys, floor / ceilingTreeMap, TreeSet
Smallest firstPriorityQueue
Largest firstnew PriorityQueue<>(Collections.reverseOrder())

Snippets

Map<String, Integer> cnt = new HashMap<>();
cnt.merge(w, 1, Integer::sum);          // count
int c = cnt.getOrDefault(w, 0);

Deque<Integer> st = new ArrayDeque<>(); // push, pop, peek
Deque<Integer> q = new ArrayDeque<>();  // offer, poll, peek

PriorityQueue<int[]> pq =
    new PriorityQueue<>((a, b) -> Integer.compare(a[0], b[0]));

TreeMap<Integer, Integer> tm = new TreeMap<>();
Integer f = tm.floorKey(x);            // largest key <= x, or null
solulu Pro

Continue this cheat sheet with Pro

Inside: 8 sections.

  • Which collection?
  • Snippets
  • Sorting
  • Strings
  • Integer traps
  • Arrays and helpers
  • +2 more
Lifetime ₹1,999 ₹999 · Launch offer
Mark this as done when you are finished.

Item 6 of 12 · updated 2026-10-13