Java 8: Method references (::) for cleaner code

Method references are shorthand for lambdas that just call an existing method.

Code
List<String> names = List.of("ava", "ben", "cara");
names.stream()
     .map(String::toUpperCase)
     .forEach(System.out::println);
Output
AVA
BEN
CARA
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-07-26