Java Guide
Java Guide
Introduction, learning path, language basics, and collections reference for solving LeetCode problems in Java
Introduction
This guide is for developers who want to solve algorithm problems in Java — whether you are new to the language or switching from C++/Python. It complements the LeetCode Templates collection: templates assume you already know which Java APIs to reach for; this guide teaches how Java works and when to use each tool.
Official references worth bookmarking:
- Java SE 21 API documentation — authoritative
java.utilreference - Java language changes (21+) — records, pattern matching, sequenced collections
- LeetCode problem set — pick Java in the language dropdown when submitting
Learning path
A practical order: language → collections → patterns → templates → timed practice.
- Language — primitives, arrays, strings, control flow, classes. Start with Language Basics.
- Collections —
HashMap,HashSet,Deque,PriorityQueue. See Collections framework and the Quick Reference. - Patterns — two pointers, sliding window, BFS/DFS, binary search. Covered in Common LeetCode templates.
- Templates — category-specific copy-paste code. Open the LeetCode Templates hub.
- Practice — work through problems by difficulty. Use the Questions List.
LeetCode Beginner's Guide
Topics: What LeetCode is, difficulty levels, constraint cheat sheet, phased roadmap (foundations → patterns → contests), Blind 75, practical tips
Language Basics
Topics: Program structure, types & variables, arrays, strings, control flow, methods & classes, collections framework, sorting & binary search, ListNode/TreeNode, sample usages, common templates, modern Java (21→26), tips & pitfalls
Collections Quick Reference
Topics: Compact API lookup for strings, arrays, ArrayList, HashMap, HashSet, TreeMap, PriorityQueue, Deque, Arrays/Collections utilities — ideal while coding under time pressure
LeetCode Templates
Topics: Category collections (graph, DP, heap, trees, etc.) — use after you are comfortable with Java syntax and core collections
LeetCode Questions List
Topics: All solved problems in this blog, organized by difficulty and category — apply what you learn from the guide
Quick start checklist
- Can you declare
int[], iterate with enhancedfor, and useString.charAt? - Do you know when to use
HashMapvsHashSetvsPriorityQueue? - Can you write a BFS with
Queueand a DFS withDequeas stack? - Have you skimmed one template page (e.g. Graph) before attempting graph problems?
If any answer is “not yet,” work through Language Basics first.