I\'m looking to use guava\'s Joiner
to join List
into one string, but with surrounding strings around each one in the list. So I want
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"; }
}));
How about
String str = "your guest " + Joiner.on(" is here, your guest ").join(names) + " is here";
if Joiner is not a must you can use String.format()
public static void main(String[] args) {
List<String> names = Arrays.asList("John", "Mary", "Henry");
StringBuilder builder = new StringBuilder();
for(int i=0; i<names.size();i++){
builder.append(String.format("your guest %s is here, ", names.get(i)));
}
System.out.println(builder.substring(0,builder.length()-2).toString());
}