merge() appends another StringJoiner's already-joined content as a single unit into this one, separated by this joiner's own delimiter, rather than re-joining its individual elements. The other joiner's own prefix and suffix are stripped off in the process.
StringJoiner names = new StringJoiner(", ");
names.add("Ann").add("Bo");
StringJoiner cities = new StringJoiner(", ");
cities.add("Rome").add("Oslo");
names.merge(cities);
System.out.println(names);
Ann, Bo, Rome, Oslo
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