Useful Built-in Classes (Math, Arrays, Objects) in Java
Beyond the core language, Java's standard library ships several extremely commonly-used utility classes worth knowing well: Math offers static methods for anything beyond basic arithmetic — sqrt, pow, abs, max, min, and many more — Arrays offers static utility methods for working with plain arrays — sort, a proper toString for readable printing, equals for content comparison, and fill for filling every slot with one value — and Objects offers null-safe utility methods, most usefully equals(a, b), which safely compares two references even if either one might be null.
All of these are static utility classes, meaning every method is called directly through the class name with no object to create first. Reaching for one of these well-tested, already-optimized methods is almost always a better choice than hand-rolling the equivalent logic from scratch.
Math
Static methods for anything beyond basic arithmetic: sqrt, pow, abs, max, min, and many more, all callable with no object to create.
Arrays.sort() and Arrays.toString()
Sort a plain array in place, and produce a properly formatted, readable String for printing it.
Arrays.equals()
Compares two arrays' contents element by element, unlike ==, which would only compare their references.
Objects.equals(a, b)
Null-safely compares two references, returning true if both are null, avoiding a NullPointerException a direct a.equals(b) could throw if a were null.
All static utility classes
Every method here is called through the class name directly, with no object of Math, Arrays, or Objects ever needing to be created.
import java.util.Arrays;import java.util.Objects; public class BuiltinClassesDemo { public static void main(String[] args) { int[] numbers = {3, 1, 2}; Arrays.sort(numbers); System.out.println("Sorted: " + Arrays.toString(numbers)); String a = null; System.out.println("Null-safe equals: " + Objects.equals(a, "hi")); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.