Multiple loops with the same logic just different fields

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.

Leave a Comment

Your email address will not be published.

Scroll to Top