distinct() — removes duplicate elements. filter() — removes elements by condition. Think of distinct() as a deduplication filter, while filter() as a selective sieve.
distinct():
equals() and hashCode() for comparison.1List<Integer> result = List.of(1,2,2,3,3,3).stream()2 .distinct()3 .toList();4// [1, 2, 3]
filter():
Predicate.1List<Integer> result = List.of(1,2,3,4,5).stream()2 .filter(x -> x % 2 == 0)3 .toList();4// [2, 4]
Key difference: