How does findFirst() work in Java streams?

findFirst() is a short-circuiting terminal Stream operation that returns the first element of the stream in encounter order, wrapped in an Optional.

Key Points

Example

Given the list [7, 3, 9, 1], calling findFirst() returns an Optional containing 7, the first element in the stream's order.

Optional<Integer> first = numbers.stream()
        .findFirst();

Common Mistakes

Follow-up Questions

Interview Tip

A concise interview answer is

findFirst() returns the first element of the stream in encounter order, wrapped in an Optional to safely handle an empty stream. Unlike findAny(), it guarantees ordering even on parallel streams, which can make it marginally slower but more predictable.

Last updated: 11 November 2026

Previous question: How does noneMatch() work in Java streams?

Next question: How do you use flatMap() to flatten nested lists in Java streams?

More Stream API Coding Questions - Level I interview questions

All Stream API Coding Questions - Level I questions