Collections.replaceAll(list, old, new) replaces every occurrence of one value with another throughout the list, unlike List.replaceAll which takes a transforming function.
List<String> tags = new ArrayList<>(List.of("todo", "done", "todo", "blocked"));
Collections.replaceAll(tags, "todo", "pending");
System.out.println("After replaceAll: " + tags);
After replaceAll: [pending, done, pending, blocked]
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-09-27