Files
2022-12-23 13:26:29 +00:00

14 lines
514 B
Java

// "Collapse loop with stream 'collect()'" "true-preview"
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Main {
List<String> test(Map<String, List<String>> map, int limit) {
List<String> list = map.entrySet().stream().filter(entry -> entry.getValue() != null).filter(entry -> entry.getValue().stream().anyMatch(str -> str.contains("foo"))).limit(limit).map(Map.Entry::getKey).collect(Collectors.toList());
return list;
}
}