Java Streams - DoubleStream distinct() example








DoubleStream distinct() returns a stream consisting of the distinct elements of this stream.

Syntax

distinct has the following syntax.

DoubleStream distinct()

Example

The following example shows how to use distinct.

import java.util.stream.DoubleStream;
//from  w  ww  .j  a  v  a 2 s.com
public class Main {
  public static void main(String[] args) {
    DoubleStream d = DoubleStream.of(1.2,1.2,2.3,4.5);
    
    DoubleStream r = d.distinct();
     
    r.forEach(System.out::println);
  }
}

The code above generates the following result.