LongStream distinct() example

Description

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

Syntax

distinct has the following syntax.


LongStream distinct()

Example

The following example shows how to use distinct.


import java.util.stream.LongStream;
//w  w w .j a v  a  2  s  . co  m
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 1L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.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