Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
The accept() method in Java Stream.Builder
Add an element to the stream using the accept() method of Java Stream.Builder.
The following is the syntax:
void accept(T t)
Here, t is the argument to be inserted.
Import the following package for the Stream.Builder class in Java:
import java.util.stream.Stream;
First, declare a Stream.Builder:
Stream.Builder<String> builder = Stream.builder();
Now, use the accept() method:
builder.accept("Demo");
builder.accept("Text");
The following is an example displaying how to implement accept() method of Stream.Builder in Java:
Example
import java.util.stream.Stream;
public class Demo {
public static void main(String[] args){
Stream.Builder<String> builder = Stream.builder();
builder.accept("Demo");
builder.accept("Text");
Stream<String> str = builder.build();
str.forEach(System.out::println);
}
}
output
Demo Text
Advertisements
