Java Method References — Free Java Tutorial
Learn Java Method References in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Java Method References in Java with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Java Method References in Java
A method reference is a shorthand for a lambda expression that calls a single existing method. Syntax: ClassName::methodName or instance::methodName.
Four types: (1) Static method: ClassName::staticMethod, (2) Instance method of a specific object: obj::method, (3) Instance method of an arbitrary instance: ClassName::instanceMethod, (4) Constructor reference: ClassName::new.
Method references improve readability when a lambda does nothing but call a method: s -> s.toUpperCase() becomes String::toUpperCase.
They work wherever a functional interface is expected — any context that accepts a lambda.
Java Method References — Syntax
// Lambda vs Method Reference list.forEach(s -> System.out.println(s)); // lambda list.forEach(System.out::println); // method ref list.stream().map(s -> s.toUpperCase()) // lambda list.stream().map(String::toUpperCase) // method ref (instance method) Arrays.sort(arr, (a,b) -> In
Learn Java Method References step by step with Syllab's free interactive Java tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Java course →