Extracting the first name from a list of full-name strings is a map() transformation that splits each string on whitespace and takes the first token.
Given the list ["Alice Johnson", "Bob Harris", "Charlie Lou"], mapping with name -> name.split(" ")[0] produces ["Alice", "Bob", "Charlie"].
List<String> fullNames = Arrays.asList(
"Alice Johnson", "Bob Harris", "Charlie Lou");
List<String> firstNames = fullNames.stream()
.map(name -> name.split(" ")[0])
.collect(Collectors.toList());A concise interview answer is
I map each full name string by splitting on a space and taking index zero of the resulting array, then collect the results into a list of first names. It's a simple approach that assumes a straightforward two-part name format.
Last updated: 11 November 2026
Previous question: How does findAny() work in Java streams?
Next question: How does allMatch() work in Java streams?