How do you get the first names from a list of full names using Java streams?

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.

Key Points

Example

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());

Interview Tip

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?

More Stream API Coding Questions - Level I interview questions

All Stream API Coding Questions - Level I questions