IntStream distinct() example

Description

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;
/*from  w w  w  .jav a 2s.c o  m*/
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.





















Home »
  Java Streams »
    Reference »




Collectors
DoubleStream
DoubleStream.Builder
IntStream
IntStream.Builder
LongStream
LongStream.Builder
Stream
Stream.Builder