The 30 second answer
I filter employees whose name is non-null and starts with the prefix, then collect to a list. I ask about case sensitivity and null names up front so we do not argue about edge cases after coding.
Could you say this in an interview?
List<Employee> r = emps.stream()
.filter(e -> e.name() != null && e.name().startsWith(prefix))
.toList();Ask about case sensitivity (regionMatches(true, 0, prefix, 0, prefix.length())) and null names before coding.
Sources (1)
- Stream.filter / toListdocs.oracle.com