LongStream distinct() is a method in java.util.stream.LongStream. 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.
LongStream distinct() Where, LongStream is a sequence of primitive long-valued elements.
Below given are some examples to understand the function in a better way.
Example 1 : Printing distinct elements of Long stream.
2 3 5 6 8
Example 2 : Counting value of distinct elements in a stream.