Worked example
List<Integer> nums = List.of(5, 3, 5, 9, 1, 3);
nums.stream().distinct().count(); // 4
nums.stream().sorted().collect(Collectors.toList()); // [1, 3, 3, 5, 5, 9]
nums.stream().distinct().sorted().collect(Collectors.toList()); // [1, 3, 5, 9]
Operations chain in the order you write them, and each one passes what is left to the next. The last call decides the shape of the answer: a number from count, a list from collect.
Note what the last line replaces: a TreeSet, a loop and a conversion — in one readable line.