IntStream distinct() is a method in java.util.stream.IntStream. This method returns a stream consisting of the distinct elements. This is a stateful intermediate operation i.e, it may incorporate state from previously seen elements when processing new elements.
IntStream distinct() Where, IntStream is a sequence of primitive int-valued elements.
Below given are some examples to understand the function in a better way.
Example 1 : Printing distinct elements of Integer stream.
2 3 5 6 8
Example 2 : Counting value of distinct elements in a stream.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.