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 add() method in Java Stream.Builder
Use the add() method to insert elements in the Stream.Builder. The element to be added is a parameter for the add().
The following is the syntax:
default Stream.Builder<T> add(T t)
Here, t is the element to be added.
Import the following package for the Stream.Builder class in Java:
import java.util.stream.Stream;
At first, create Stream.Builder:
Stream.Builder<String> builder = Stream.builder();
Now, add elements using add() method:
builder.add("This");
builder.add("is");
builder.add("it!");
Here is an example displaying how to implement add() 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.add("This");
builder.add("is");
builder.add("it!");
Stream<String> str = builder.build();
str.forEach(System.out::println);
}
}
output
This is it!
Advertisements
