Close

Java 8 Streams - IntStream.distinct Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

IntStream distinct()

Returns a stream consisting of the distinct elements.

This is a stateful intermediate operation.

Examples


package com.logicbig.example.intstream;

import java.util.stream.IntStream;

public class DistinctExample {

public static void main(String... args) {
IntStream intStream = IntStream.of(4, 2, 3, 2, 3, 4);
intStream.distinct().forEach(System.out::println);

}
}

Output

4
2
3




See Also