sorted() with no arguments sorts the elements of a stream in their natural order, which is ascending for numbers. It returns a new stream, so the original list stays unchanged.
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class SortValues {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(10, 15, 8, 49, 25, 98, 98, 32, 15);
List<Integer> sorted = list.stream()
.sorted()
.collect(Collectors.toList());
System.out.println(sorted);
System.out.println(list); // original order is unchanged
}
}[8, 10, 15, 15, 25, 32, 49, 98, 98]
[10, 15, 8, 49, 25, 98, 98, 32, 15]
Mention that sorted() keeps duplicates. Add distinct() before it if the interviewer wants unique sorted values. For objects, use sorted(Comparator.comparing(Employee::getSalary)).
A concise interview answer is
I call stream().sorted(), which sorts in natural ascending order and returns a new stream, then collect it into a list. The original list stays unchanged; if I want to sort in place I use list.sort(null) instead.
Last updated: 11 November 2026
Previous question: Given a string, find the first repeated character using streams.
Next question: Given a list of integers, sort the values in descending order using streams.