// "Collapse loop with stream 'collect()'" "true-preview" import java.util.*; import java.util.stream.Collectors; public class Main { public Set test(String[] array) { /*initial count*/ Set set = Arrays.stream(array).filter(Objects::nonNull).limit(10).collect(Collectors.toSet()); return set; } }