// "Collapse loop with stream 'forEach()'" "true-preview" import java.util.*; public class Collect { class Person { String getName() { return ""; } } void collectNames(List persons){ Set names = new HashSet<>(); names.add("Test"); persons.stream().map(Person::getName).forEach(names::add); System.out.println(names); } }