Syntax error DoubleStream.Builder accept() method in Java

DoubleStream.Builder accept() method in Java



The accept() method of the DoubleStream class in Java adds an element to the stream being built.

The syntax is as follows −

void accept(double ele)

Here, ele is the element to be inserted into the stream.

To use the DoubleStream.Builder class in Java, import the following package −

import java.util.stream.DoubleStream;

The following is an example to implement DoubleStream.Builder() accept() method in Java −

Example

 Live Demo

import java.util.stream.DoubleStream;

public class Demo {
   public static void main(String[] args) {
      DoubleStream.Builder builder = DoubleStream.builder();
      builder.accept(12.9);
      builder.accept(25.6);
      builder.accept(35.8);
      builder.accept(43.9);
      builder.accept(56.3);
      builder.accept(67.4);
      builder.accept(78.8);
      builder.accept(89.4);
      builder.build().forEach(System.out::println);
   }
}

Output

12.9
25.6
35.8
43.9
56.3
67.4
78.8
89.4
Updated on: 2019-07-30T22:30:25+05:30

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements