Java Streams - IntStream distinct() example








IntStream distinct() returns a stream consisting of the distinct elements of this stream. This is a stateful intermediate operation.

Syntax

distinct has the following syntax.

IntStream distinct()

Example

The following example shows how to use distinct.

import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    IntStream i = IntStream.of(6,5,7,1, 2, 3, 3);
    i.distinct()
     .forEach(System.out::println);
  }
}

The code above generates the following result.