coderef

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.

  • Hello world
  • Variables
  • Constant
  • Print
  • Read input
  • Convert types

Strings

Text manipulation.

  • Length / character
  • Compare
  • Contains / index
  • Substring
  • Case / trim
  • Split / join
  • Format
  • Build efficiently
  • Text block

Arrays & collections

Lists, maps and sets.

  • 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.

  • If / else
  • Ternary
  • Switch expression
  • For loops
  • While
  • Pattern matching

Classes & records

Object-oriented code.

  • Class
  • Inheritance
  • Interface
  • Record (immutable data)
  • Enum
  • Static method

Streams & lambdas

Functional-style processing.

  • Lambda
  • Filter and map
  • Sum
  • Group by
  • Optional

Exceptions & files

Errors and I/O.

  • Try / catch
  • Throw
  • Try-with-resources
  • Read / write a file

← All quick references