replaceAll applies a BiFunction to each entry in place, which is cleaner than iterating the entry set and calling setValue.
Map<String, String> headers = new TreeMap<>();
headers.put("accept", "application/json");
headers.put("host", "javacodinghub.com");
headers.replaceAll((key, value) -> value.toUpperCase());
System.out.println(headers);
Map<String, Integer> prices = new TreeMap<>(Map.of("pen", 100, "book", 250));
prices.replaceAll((item, price) -> price * 2);
System.out.println("doubled: " + prices);
{accept=APPLICATION/JSON, host=JAVACODINGHUB.COM}
doubled: {book=500, pen=200}
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-30