Lets say we have a simple method that should concat all names of a Person collection and return the result string.
public String concantAndReturnNames(final Collection<Person> persons) {
String result = "";
for (Person person : persons) {
result += person.getName();
}
return result;
}
Is there a way to write this code with new stream API forEach function in 1 line?