LongStream distinct() in Java with examples
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.
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
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.