You can try this
public <T, R> String join(Collection<T> collection, Function<T, R> mapper) {
return collection.stream()
.map(mapper)
.map(String::valueOf)
.collect(Collectors.joining(", "));
}
CLICK HERE to find out more related problems solutions.