Is there a way to join strings, each with a specific surrounding string?

guava, java, string

Solution

The way to do this is with a transform, first:

 Joiner.on(", ").join(Iterables.transform(names, new Function<String, String>() {
   public String apply(String str) { return "your guest " + str + " is here"; }
 }));

Problem

I'm looking to use guava's `Joiner` to join `List<String>` into one string, but with surrounding strings around each one in the list. So I want to take a list of Strings: ``` List<String> names = Arrays.asList("John", "Mary", "Henry"); ``` and generate this one string: ``` "your guest John is here, your guest Mary is here, your guest Henry is here" ``` The examples I see of using `Joiner` seem to be to generate the 3 names separated by a comma, but I'm looking to surround each string with some extra strings (the same ones every time). I hope I'm being clear enough here. Thanks for your help.

Original source

Related problems