Java Quick Reference
Java essentials: types, strings, arrays, collections, control flow, methods, classes, records, streams and exceptions.
7 sections · 46 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Program structure and variables.
TaskCode
- Hello world
- Variables
- Constant
- Read input
- Convert types
Strings
Text manipulation.
TaskCode
- Length / character
- Compare
- Contains / index
- Substring
- Case / trim
- Split / join
- Format
- Build efficiently
- Text block
Arrays & collections
Lists, maps and sets.
TaskCode
- Array
- Sort an array
- List
- Add / get / remove
- Size / contains
- Sort a list
- Reverse a list
- Map
- Loop over a map
- Set
Control flow
Conditions and loops.
TaskCode
- If / else
- Ternary
- Switch expression
- For loops
- While
- Pattern matching
Classes & records
Object-oriented code.
TaskCode
- Class
- Inheritance
- Interface
- Record (immutable data)
- Enum
- Static method
Streams & lambdas
Functional-style processing.
TaskCode
- Lambda
- Filter and map
- Sum
- Group by
- Optional
Exceptions & files
Errors and I/O.
TaskCode
- Try / catch
- Throw
- Try-with-resources
- Read / write a file