findFirst() returns the first element of a stream wrapped in an Optional, because the stream might be empty. You then read the value safely with ifPresent(), orElse() or similar methods.
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class FindFirstElement {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(10, 15, 8, 49, 25, 98, 98, 32, 15);
list.stream()
.findFirst()
.ifPresent(System.out::println);
// Safe default for an empty list
List<Integer> empty = Collections.emptyList();
int first = empty.stream().findFirst().orElse(-1);
System.out.println(first);
}
}10
-1
Expect the follow-up "What is the difference between findFirst() and findAny()?" findFirst() respects encounter order. findAny() is free to return any element, which helps performance in parallel streams.
A concise interview answer is
I call stream().findFirst(), which returns an Optional because the list might be empty, and read it safely with ifPresent or orElse. For an ordered list it always returns the first element; findAny is the alternative when order doesn't matter, especially in parallel streams.
Last updated: 11 November 2026
Previous question: How do you find duplicate elements in a list of integers using streams?
Next question: Given a list of integers, count the elements using streams.